Compare commits
367 Commits
edk2-stabl
...
master
Author | SHA1 | Date | |
---|---|---|---|
71606314f8 | |||
90cb1ec332 | |||
603ad2d6ae | |||
65b0d08786 | |||
b45aff0dc9 | |||
10ab1c67c4 | |||
10cd8b45ce | |||
e2e09d8512 | |||
7772e339bd | |||
cac1ea6c2a | |||
de4cc40b8c | |||
839bd17973 | |||
077760fec4 | |||
e3b3e907e1 | |||
d390b163f8 | |||
341ee5c31b | |||
525578bdd5 | |||
cdc1a88272 | |||
669291db5a | |||
fcd09b1edb | |||
68310cd56a | |||
ffb8481ba8 | |||
7421ea1f2a | |||
b7db4d895a | |||
db4101c308 | |||
ad245ffeff | |||
3a516aa240 | |||
32a9ee736e | |||
52a4bc65f6 | |||
87f22f4b5c | |||
27b044605c | |||
b0930e3f4e | |||
de2330450f | |||
7339bfeffa | |||
3b36aa96de | |||
7c584bb048 | |||
746cc5cc40 | |||
5f68a363d0 | |||
a8dc6bf73f | |||
ced13b93af | |||
e784848116 | |||
9518d77eb8 | |||
c695e3182a | |||
cd4cebabf5 | |||
843f2d0964 | |||
30b6d08e27 | |||
b40c64ec25 | |||
79655e2768 | |||
55f8bddade | |||
0e3189d406 | |||
08281572aa | |||
ed7a3143b7 | |||
3096fcf81d | |||
27a7345882 | |||
b5412646db | |||
e065735b1b | |||
acfd991b68 | |||
40fa5cf299 | |||
f44cc28972 | |||
8deeda7ce0 | |||
1d8fedb0cd | |||
88a4de450f | |||
3e722403cd | |||
66c69871e7 | |||
c98f7f7550 | |||
865229bcc8 | |||
4ddf2448ed | |||
9440986d4e | |||
32460bb5b1 | |||
207b6d68a0 | |||
dff3d3811f | |||
4afb939531 | |||
72a9ef1c8a | |||
1904a64bcc | |||
4c4ceb2ceb | |||
a85336531c | |||
e10d83234c | |||
677204f941 | |||
cb9d711891 | |||
4f58e0cf99 | |||
024a291b3e | |||
319bb7223a | |||
7142e64841 | |||
284dbac43d | |||
558a25366d | |||
4b6ee06a09 | |||
3c0b84420f | |||
25996a3441 | |||
b82c9631da | |||
f3b0ee0cee | |||
09340de246 | |||
6fd2d58d5d | |||
b538d6a1b1 | |||
b04e11b4c4 | |||
5cbfb93abe | |||
952b5cf94c | |||
82b0358e3f | |||
5590cefe93 | |||
916f495e77 | |||
efc7ccf906 | |||
fa7fdb89a3 | |||
2727231b0a | |||
23ed7f209c | |||
6b3a89a9fd | |||
4a6400b084 | |||
04c36d5a1b | |||
6a468a8b55 | |||
3dfd64305b | |||
47f212295f | |||
c56ea95b28 | |||
9783dc01cc | |||
7421094136 | |||
42e8fa84f7 | |||
51fcd2023b | |||
af9b851732 | |||
987bea6525 | |||
1c0d4ae2c0 | |||
c12bbc1490 | |||
17f333f2a4 | |||
7097c97bde | |||
370c55b2ba | |||
24fa360857 | |||
248aa153f6 | |||
fecf55a66a | |||
f0ed194236 | |||
fd290ab862 | |||
5f783827bb | |||
5d4c5253e8 | |||
ec6e59aefe | |||
1699845c5f | |||
3a4efc98b0 | |||
3d87214a20 | |||
fcce7f77e6 | |||
748d57d40f | |||
5e31c5666d | |||
e942b85a21 | |||
0c74aa2073 | |||
88781ccd74 | |||
54a4fd9b35 | |||
9bc2725198 | |||
cf3b34c0b8 | |||
750d763623 | |||
c3f615a1bd | |||
d8e4c4b000 | |||
74db2ed3e5 | |||
5f391c6606 | |||
338fd26b8f | |||
094727264f | |||
c0dfe3ec1f | |||
66c24219ad | |||
90b6725562 | |||
d97f964f7c | |||
e3fa6986ae | |||
86c8d69146 | |||
680030a6ec | |||
7dd7b89058 | |||
f29160a896 | |||
506740982b | |||
ddc43e7a41 | |||
538b8944c1 | |||
d0906f602b | |||
be92e09206 | |||
6780b3aba0 | |||
1dc752d903 | |||
8b02ecc5f0 | |||
6dc09fda04 | |||
390b10b548 | |||
7dec566775 | |||
0afb874349 | |||
47001ab989 | |||
a010681f74 | |||
28fecae8a3 | |||
18fdffe825 | |||
b505f11f39 | |||
5a67a2efa7 | |||
f6bf37c171 | |||
ee89b59430 | |||
6ced1e91ef | |||
789727ccf3 | |||
d2b18e6bc2 | |||
30d274e354 | |||
c0bf953fe8 | |||
8ccbf075f0 | |||
069f9911a3 | |||
2b330b57db | |||
f40c1f2a30 | |||
5fe9db0f82 | |||
6b14ef6b28 | |||
4bd3b5ab13 | |||
5bdb091133 | |||
8a6471819b | |||
c212fec9cf | |||
61185f1d50 | |||
93fac4fd7b | |||
c98fbda328 | |||
93ff80a218 | |||
71aaf7a308 | |||
fcfdbe2987 | |||
b6cd5ddce9 | |||
32e2968a1e | |||
7ea05d8fe9 | |||
bfcf2d66c7 | |||
6363872629 | |||
0b2f97c00a | |||
abaf405ed9 | |||
392a368533 | |||
032830e968 | |||
c5fb47ddab | |||
78e5019071 | |||
7750468c37 | |||
439030bc37 | |||
cc63e04afc | |||
022ddb8f84 | |||
fecca982e3 | |||
18ad6485a9 | |||
70892b13b2 | |||
74f6ce6734 | |||
da7858117f | |||
b594fba4ec | |||
de95e919be | |||
31cd5ee8c0 | |||
5ba3602e45 | |||
d77efa2ebe | |||
0707d9296d | |||
e25808f501 | |||
98f150a954 | |||
963671d380 | |||
665789b61b | |||
013006e4ef | |||
543add1d41 | |||
932db9df0c | |||
b7f8779fe1 | |||
3d5352d934 | |||
6ddfbeb0d6 | |||
f1203a4099 | |||
c98c14576f | |||
503344cdbd | |||
89ff5da9f9 | |||
ee28bea4c0 | |||
8707f835ae | |||
ee249efe8c | |||
6fb3cc05dc | |||
79d4d8a81c | |||
2e4e41d012 | |||
c8f56800fd | |||
b0be42516e | |||
29114fc574 | |||
b387114113 | |||
7cc2010f46 | |||
b79a64d26e | |||
e043e3e3bf | |||
8f698f0a64 | |||
d402de2222 | |||
278250045b | |||
37f63deeef | |||
596f856c13 | |||
1fb6462c67 | |||
7fde22823d | |||
e4e1f6229c | |||
cf58f47623 | |||
4b9312de05 | |||
7f1ffba5de | |||
35f6a2780e | |||
a1a6da80aa | |||
07c49d5d40 | |||
3840c35e34 | |||
ccbbc2a5c8 | |||
e7486b5064 | |||
68461c2c37 | |||
bf8f16f771 | |||
019feb42a1 | |||
5572b43c67 | |||
308e6e0936 | |||
6b3a512149 | |||
6f67ed45e0 | |||
a8b80149e1 | |||
ddaf39263a | |||
ccf91b518f | |||
1c0db23151 | |||
18fc96c9a9 | |||
1e603ac0d8 | |||
063a831c66 | |||
f71a76ee01 | |||
91460083f1 | |||
524feaa32f | |||
9f9bf82209 | |||
1fbc121cfe | |||
da4aa451ba | |||
e60529df58 | |||
2a0d4a2641 | |||
918288ab5a | |||
bff9815b61 | |||
1ae5bee967 | |||
855f528199 | |||
970aacd191 | |||
3775122ede | |||
47723854fd | |||
275d0a39c4 | |||
318b0d714a | |||
49b7faba1d | |||
e3bd782373 | |||
b7a97bfac5 | |||
4329b5b0cd | |||
52e44713d2 | |||
fded08e744 | |||
371940932d | |||
2ec8f0c640 | |||
049ff6c39c | |||
17b2872200 | |||
ae1079b386 | |||
dcffad2491 | |||
d159e22913 | |||
dc7cfa9bab | |||
bac9c74080 | |||
adebfe121c | |||
13fbc16556 | |||
73ac735be8 | |||
d9a6e7b0b8 | |||
d4c76fa17d | |||
422dfaab31 | |||
9da786c16f | |||
0ce2012c6c | |||
1988f2df29 | |||
3e91e42136 | |||
6d571c0070 | |||
0bbec15b54 | |||
45ad13bb64 | |||
dae8c29dab | |||
e59a40b92c | |||
aceb3490a2 | |||
3ad1d7eb7b | |||
8757e648d1 | |||
9d32a02a72 | |||
ba9c3ceaf8 | |||
e7a7169446 | |||
74b5309da9 | |||
33c81c25bb | |||
d25421d0d8 | |||
5e09b5d6d7 | |||
c8e77454b5 | |||
e2c9d8eba4 | |||
b485230462 | |||
a3ee1eea96 | |||
1f161a7915 | |||
68238d4f94 | |||
44fdc4f398 | |||
d0c0e1960a | |||
ba96acd963 | |||
f881b4d129 | |||
bc982869dd | |||
8d7c48e0e7 | |||
6bb39cfd00 | |||
a7a0443751 | |||
796e1b82df | |||
65200edb3a | |||
bda5b4a6cf | |||
7f17a15564 | |||
b25f84d7b3 | |||
efca2c6cfc | |||
2cb466cc2c | |||
7fa4a984c4 | |||
11ad164bce | |||
8ccd63d14d | |||
c10e5703fe | |||
2f4b07b668 | |||
2ca8d55974 | |||
d698bcfe4f |
27
.github/pull_request_template.md
vendored
Normal file
27
.github/pull_request_template.md
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
# Description
|
||||
|
||||
<_Include a description of the change and why this change was made._>
|
||||
|
||||
<_For each item, place an "x" in between `[` and `]` if true. Example: `[x]` (you can also check items in GitHub UI)_>
|
||||
|
||||
<_Create the PR as a Draft PR if it is only created to run CI checks._>
|
||||
|
||||
<_Delete lines in \<\> tags before creating the PR._>
|
||||
|
||||
- [ ] Breaking change?
|
||||
- **Breaking change** - Will this cause a break in build or boot behavior?
|
||||
- Examples: Add a new library class or move a module to a different repo.
|
||||
- [ ] Impacts security?
|
||||
- **Security** - Does the change have a direct security impact?
|
||||
- Examples: Crypto algorithm change or buffer overflow fix.
|
||||
- [ ] Includes tests?
|
||||
- **Tests** - Does the change include any explicit test code?
|
||||
- Examples: Unit tests or integration tests.
|
||||
|
||||
## How This Was Tested
|
||||
|
||||
<_Describe the test(s) that were run to verify the changes._>
|
||||
|
||||
## Integration Instructions
|
||||
|
||||
<_Describe how these changes should be integrated. Use N/A if nothing is required._>
|
37
.github/workflows/codeql.yml
vendored
37
.github/workflows/codeql.yml
vendored
@ -79,7 +79,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Python
|
||||
uses: actions/setup-python@v4
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
cache: 'pip'
|
||||
@ -136,15 +136,26 @@ jobs:
|
||||
print(f'ci_setup_supported={str(ci_setup_supported).lower()}', file=fh)
|
||||
print(f'setup_supported={str(setup_supported).lower()}', file=fh)
|
||||
|
||||
- name: Convert Arch to Log Format
|
||||
id: convert_arch_hyphen
|
||||
env:
|
||||
ARCH_LIST: ${{ matrix.ArchList }}
|
||||
shell: python
|
||||
run: |
|
||||
import os
|
||||
|
||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
|
||||
print(f'arch_list={os.environ["ARCH_LIST"].replace(",", "-")}', file=fh)
|
||||
|
||||
- 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=VS2019
|
||||
|
||||
- name: Upload Setup Log As An Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: (success() || failure()) && steps.get_ci_file_operations.outputs.setup_supported == 'true'
|
||||
with:
|
||||
name: ${{ matrix.Package }}-Logs
|
||||
name: ${{ matrix.Package }}-${{ steps.convert_arch_hyphen.outputs.arch_list }}-Setup-Log
|
||||
path: |
|
||||
**/SETUPLOG.txt
|
||||
retention-days: 7
|
||||
@ -155,10 +166,10 @@ jobs:
|
||||
run: stuart_ci_setup -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2019
|
||||
|
||||
- name: Upload CI Setup Log As An Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: (success() || failure()) && steps.get_ci_file_operations.outputs.ci_setup_supported == 'true'
|
||||
with:
|
||||
name: ${{ matrix.Package }}-Logs
|
||||
name: ${{ matrix.Package }}-${{ steps.convert_arch_hyphen.outputs.arch_list }}-CI-Setup-Log
|
||||
path: |
|
||||
**/CISETUP.txt
|
||||
retention-days: 7
|
||||
@ -168,10 +179,10 @@ jobs:
|
||||
run: stuart_update -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2019
|
||||
|
||||
- name: Upload Update Log As An Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: success() || failure()
|
||||
with:
|
||||
name: ${{ matrix.Package }}-Logs
|
||||
name: ${{ matrix.Package }}-${{ steps.convert_arch_hyphen.outputs.arch_list }}-Update-Log
|
||||
path: |
|
||||
**/UPDATE_LOG.txt
|
||||
retention-days: 7
|
||||
@ -228,7 +239,7 @@ jobs:
|
||||
|
||||
- name: Attempt to Load CodeQL CLI From Cache
|
||||
id: codeqlcli_cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.cache_key_gen.outputs.codeql_cli_ext_dep_dir }}
|
||||
key: ${{ steps.cache_key_gen.outputs.codeql_cli_cache_key }}
|
||||
@ -284,10 +295,10 @@ jobs:
|
||||
delete_dirs(build_path)
|
||||
|
||||
- name: Upload Build Logs As An Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: success() || failure()
|
||||
with:
|
||||
name: ${{ matrix.Package }}-Logs
|
||||
name: ${{ matrix.Package }}-${{ steps.convert_arch_hyphen.outputs.arch_list }}-Build-Logs
|
||||
path: |
|
||||
**/BUILD_REPORT.TXT
|
||||
**/OVERRIDELOG.TXT
|
||||
@ -329,10 +340,10 @@ jobs:
|
||||
print(f'upload_sarif_file=false', file=fh)
|
||||
|
||||
- name: Upload CodeQL Results (SARIF) As An Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: steps.env_data.outputs.upload_sarif_file == 'true'
|
||||
with:
|
||||
name: ${{ matrix.Package }}-CodeQL-SARIF
|
||||
name: ${{ matrix.Package }}-${{ steps.convert_arch_hyphen.outputs.arch_list }}-CodeQL-SARIF
|
||||
path: |
|
||||
${{ steps.env_data.outputs.emacs_file_path }}
|
||||
${{ steps.env_data.outputs.sarif_file_path }}
|
||||
@ -340,7 +351,7 @@ jobs:
|
||||
if-no-files-found: warn
|
||||
|
||||
- name: Upload CodeQL Results (SARIF) To GitHub Code Scanning
|
||||
uses: github/codeql-action/upload-sarif@v2
|
||||
uses: github/codeql-action/upload-sarif@v3
|
||||
if: steps.env_data.outputs.upload_sarif_file == 'true'
|
||||
with:
|
||||
# Path to SARIF file relative to the root of the repository.
|
||||
|
36
.github/workflows/pr-labeler.yml
vendored
Normal file
36
.github/workflows/pr-labeler.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
# This workflow automatically applies labels to pull requests based on regular expression matches against the content
|
||||
# in the pull request.
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
# For more information, see:
|
||||
# https://github.com/github/issue-labeler
|
||||
|
||||
name: Apply Labels Based on Message Content
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types:
|
||||
- edited
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
name: Label PR from Description
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- name: Apply Labels Based on PR Description
|
||||
uses: github/issue-labeler@v3.1
|
||||
with:
|
||||
configuration-path: .github/workflows/pr-labeler/regex.yml
|
||||
enable-versioned-regex: 0
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
16
.github/workflows/pr-labeler/regex.yml
vendored
Normal file
16
.github/workflows/pr-labeler/regex.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# Specifies labels to apply to pull requests based on regular expressions.
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
# For more information, see:
|
||||
# https://github.com/github/issue-labeler
|
||||
|
||||
impact:breaking-change:
|
||||
- '\s*-\s*\[\s*[x|X]\s*\] Breaking change\?'
|
||||
|
||||
impact:security:
|
||||
- '\s*-\s*\[\s*[x|X]\s*\] Impacts security\?'
|
||||
|
||||
impact:testing:
|
||||
- '\s*-\s*\[\s*[x|X]\s*\] Includes tests\?'
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -35,3 +35,6 @@
|
||||
[submodule "CryptoPkg/Library/MbedTlsLib/mbedtls"]
|
||||
path = CryptoPkg/Library/MbedTlsLib/mbedtls
|
||||
url = https://github.com/ARMmbed/mbedtls
|
||||
[submodule "SecurityPkg/DeviceSecurity/SpdmLib/libspdm"]
|
||||
path = SecurityPkg/DeviceSecurity/SpdmLib/libspdm
|
||||
url = https://github.com/DMTF/libspdm.git
|
||||
|
@ -237,6 +237,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
|
||||
"MdePkg/Library/MipiSysTLib/mipisyst", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"CryptoPkg/Library/MbedTlsLib/mbedtls", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"SecurityPkg/DeviceSecurity/SpdmLib/libspdm", False))
|
||||
return rs
|
||||
|
||||
def GetName(self):
|
||||
|
@ -139,11 +139,6 @@
|
||||
# Define if the GICv3 controller should use the GICv2 legacy
|
||||
gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042
|
||||
|
||||
## Define the conduit to use for monitor calls.
|
||||
# Default PcdMonitorConduitHvc = FALSE, conduit = SMC
|
||||
# If PcdMonitorConduitHvc = TRUE, conduit = HVC
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x00000047
|
||||
|
||||
# Whether to remap all unused memory NX before installing the CPU arch
|
||||
# protocol driver. This is needed on platforms that map all DRAM with RWX
|
||||
# attributes initially, and can be disabled otherwise.
|
||||
@ -317,6 +312,11 @@
|
||||
gArmTokenSpaceGuid.PcdSystemBiosRelease|0xFFFF|UINT16|0x30000058
|
||||
gArmTokenSpaceGuid.PcdEmbeddedControllerFirmwareRelease|0xFFFF|UINT16|0x30000059
|
||||
|
||||
## Define the conduit to use for monitor calls.
|
||||
# Default PcdMonitorConduitHvc = FALSE, conduit = SMC
|
||||
# If PcdMonitorConduitHvc = TRUE, conduit = HVC
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x00000047
|
||||
|
||||
[PcdsFixedAtBuild.common, PcdsDynamic.common]
|
||||
#
|
||||
# ARM Architectural Timer
|
||||
|
@ -1,44 +0,0 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2012 - 2021, Arm Limited. All rights reserved.<BR>
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef ARM_CORTEX_A5X_H_
|
||||
#define ARM_CORTEX_A5X_H_
|
||||
|
||||
//
|
||||
// Cortex A5x feature bit definitions
|
||||
//
|
||||
#define A5X_FEATURE_SMP (1 << 6)
|
||||
|
||||
//
|
||||
// Helper functions to access CPU Extended Control Register
|
||||
//
|
||||
UINT64
|
||||
EFIAPI
|
||||
ArmReadCpuExCr (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmWriteCpuExCr (
|
||||
IN UINT64 Val
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmSetCpuExCrBit (
|
||||
IN UINT64 Bits
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmUnsetCpuExCrBit (
|
||||
IN UINT64 Bits
|
||||
);
|
||||
|
||||
#endif // ARM_CORTEX_A5X_H_
|
@ -1,57 +0,0 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2011, ARM Limited. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef ARM_CORTEX_A9_H_
|
||||
#define ARM_CORTEX_A9_H_
|
||||
|
||||
#include <Chipset/ArmV7.h>
|
||||
|
||||
//
|
||||
// Cortex A9 feature bit definitions
|
||||
//
|
||||
#define A9_FEATURE_PARITY (1<<9)
|
||||
#define A9_FEATURE_AOW (1<<8)
|
||||
#define A9_FEATURE_EXCL (1<<7)
|
||||
#define A9_FEATURE_SMP (1<<6)
|
||||
#define A9_FEATURE_FOZ (1<<3)
|
||||
#define A9_FEATURE_DPREF (1<<2)
|
||||
#define A9_FEATURE_HINT (1<<1)
|
||||
#define A9_FEATURE_FWD (1<<0)
|
||||
|
||||
//
|
||||
// Cortex A9 Watchdog
|
||||
//
|
||||
#define ARM_A9_WATCHDOG_REGION 0x600
|
||||
|
||||
#define ARM_A9_WATCHDOG_LOAD_REGISTER 0x20
|
||||
#define ARM_A9_WATCHDOG_CONTROL_REGISTER 0x28
|
||||
|
||||
#define ARM_A9_WATCHDOG_WATCHDOG_MODE (1 << 3)
|
||||
#define ARM_A9_WATCHDOG_TIMER_MODE (0 << 3)
|
||||
#define ARM_A9_WATCHDOG_SINGLE_SHOT (0 << 1)
|
||||
#define ARM_A9_WATCHDOG_AUTORELOAD (1 << 1)
|
||||
#define ARM_A9_WATCHDOG_ENABLE 1
|
||||
|
||||
//
|
||||
// SCU register offsets & masks
|
||||
//
|
||||
#define A9_SCU_CONTROL_OFFSET 0x0
|
||||
#define A9_SCU_CONFIG_OFFSET 0x4
|
||||
#define A9_SCU_INVALL_OFFSET 0xC
|
||||
#define A9_SCU_FILT_START_OFFSET 0x40
|
||||
#define A9_SCU_FILT_END_OFFSET 0x44
|
||||
#define A9_SCU_SACR_OFFSET 0x50
|
||||
#define A9_SCU_SSACR_OFFSET 0x54
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
ArmGetScuBaseAddress (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // ARM_CORTEX_A9_H_
|
@ -1,9 +1,15 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2015, Linaro Ltd. All rights reserved.
|
||||
* Copyright (c) 2024, Arm Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
* @par Reference(s):
|
||||
* - Arm Generic Interrupt Controller Architecture Specification,
|
||||
* Issue H, January 2022.
|
||||
* (https://developer.arm.com/documentation/ihi0069/)
|
||||
*
|
||||
**/
|
||||
|
||||
#ifndef ARM_GIC_ARCH_LIB_H_
|
||||
@ -23,4 +29,12 @@ ArmGicGetSupportedArchRevision (
|
||||
VOID
|
||||
);
|
||||
|
||||
//
|
||||
// GIC SPI and extended SPI ranges
|
||||
//
|
||||
#define ARM_GIC_ARCH_SPI_MIN 32
|
||||
#define ARM_GIC_ARCH_SPI_MAX 1019
|
||||
#define ARM_GIC_ARCH_EXT_SPI_MIN 4096
|
||||
#define ARM_GIC_ARCH_EXT_SPI_MAX 5119
|
||||
|
||||
#endif // ARM_GIC_ARCH_LIB_H_
|
||||
|
@ -26,7 +26,7 @@ ArmMonitorCall (
|
||||
IN OUT ARM_MONITOR_ARGS *Args
|
||||
)
|
||||
{
|
||||
if (FeaturePcdGet (PcdMonitorConduitHvc)) {
|
||||
if (PcdGetBool (PcdMonitorConduitHvc)) {
|
||||
ArmCallHvc ((ARM_HVC_ARGS *)Args);
|
||||
} else {
|
||||
ArmCallSmc ((ARM_SMC_ARGS *)Args);
|
||||
|
@ -78,7 +78,6 @@
|
||||
gArmTokenSpaceGuid.PcdBaseBoardManufacturer
|
||||
gArmTokenSpaceGuid.PcdBaseBoardProductName
|
||||
gArmTokenSpaceGuid.PcdBaseBoardVersion
|
||||
gArmTokenSpaceGuid.PcdFdBaseAddress
|
||||
|
||||
[Guids]
|
||||
gEfiGenericVariableGuid
|
||||
|
@ -253,7 +253,7 @@ SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor) {
|
||||
(VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE0));
|
||||
|
||||
SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
|
||||
SmbiosRecord->BiosSegment = (UINT16)(FixedPcdGet32 (PcdFdBaseAddress) / SIZE_64KB);
|
||||
SmbiosRecord->BiosSegment = 0;
|
||||
if (BiosPhysicalSize < SIZE_16MB) {
|
||||
SmbiosRecord->BiosSize = Base2ToByteWith64KUnit (BiosPhysicalSize) - 1;
|
||||
} else {
|
||||
|
@ -73,14 +73,4 @@ PeiCommonExceptionEntry (
|
||||
IN UINTN LR
|
||||
);
|
||||
|
||||
/*
|
||||
* Autogenerated function that calls the library constructors for all of the
|
||||
* module's dependent libraries.
|
||||
*/
|
||||
VOID
|
||||
EFIAPI
|
||||
ProcessLibraryConstructorList (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
INF_VERSION = 1.30
|
||||
BASE_NAME = ArmPlatformPrePeiCore
|
||||
FILE_GUID = b78d02bb-d0b5-4389-bc7f-b39ee846c784
|
||||
MODULE_TYPE = SEC
|
||||
|
@ -8,7 +8,7 @@
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
INF_VERSION = 1.30
|
||||
BASE_NAME = ArmPlatformPrePeiCore
|
||||
FILE_GUID = 469fc080-aec1-11df-927c-0002a5d5c51b
|
||||
MODULE_TYPE = SEC
|
||||
|
@ -8,7 +8,7 @@
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
INF_VERSION = 1.30
|
||||
BASE_NAME = ArmPlatformPrePiMPCore
|
||||
FILE_GUID = d959e387-7b91-452c-90e0-a1dbac90ddb8
|
||||
MODULE_TYPE = SEC
|
||||
|
@ -9,7 +9,7 @@
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
INF_VERSION = 1.30
|
||||
BASE_NAME = ArmPlatformPrePiUniCore
|
||||
FILE_GUID = 3e401783-cc94-4fcd-97bc-bd35ac369d2f
|
||||
MODULE_TYPE = SEC
|
||||
|
@ -79,10 +79,4 @@ ArchInitialize (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ProcessLibraryConstructorList (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif /* _PREPI_H_ */
|
||||
|
@ -156,7 +156,9 @@
|
||||
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
|
||||
!endif
|
||||
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
|
||||
RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
|
||||
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
|
||||
ArmTrngLib|ArmPkg/Library/ArmTrngLib/ArmTrngLib.inf
|
||||
ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf
|
||||
|
||||
#
|
||||
# Secure Boot dependencies
|
||||
@ -266,6 +268,7 @@
|
||||
|
||||
[LibraryClasses.ARM]
|
||||
ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf
|
||||
RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
|
||||
|
||||
[BuildOptions]
|
||||
GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
|
||||
|
@ -201,6 +201,9 @@
|
||||
[PcdsDynamicHii]
|
||||
gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGuid|0x0|FALSE|NV,BS
|
||||
|
||||
[PcdsPatchableInModule.common]
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Components Section - list of all EDK II Modules needed by this Platform
|
||||
|
@ -126,8 +126,6 @@
|
||||
# Use MMIO for accessing RTC controller registers.
|
||||
gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|TRUE
|
||||
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
|
||||
|
||||
[PcdsFixedAtBuild.common]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F
|
||||
|
||||
@ -167,6 +165,8 @@
|
||||
#
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
|
||||
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
|
||||
|
||||
[PcdsPatchableInModule.common]
|
||||
#
|
||||
# This will be overridden in the code
|
||||
|
@ -49,10 +49,10 @@
|
||||
|
||||
!include NetworkPkg/NetworkDefines.dsc.inc
|
||||
|
||||
!include ArmVirtPkg/ArmVirt.dsc.inc
|
||||
|
||||
!include MdePkg/MdeLibs.dsc.inc
|
||||
|
||||
!include ArmVirtPkg/ArmVirt.dsc.inc
|
||||
|
||||
[LibraryClasses.common]
|
||||
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
|
||||
ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
|
||||
@ -60,13 +60,13 @@
|
||||
# Virtio Support
|
||||
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
|
||||
VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
|
||||
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf
|
||||
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgMmioDxeLib.inf
|
||||
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
|
||||
QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParserLib.inf
|
||||
QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf
|
||||
|
||||
TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
|
||||
VirtNorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
|
||||
VirtNorFlashPlatformLib|OvmfPkg/Library/FdtNorFlashQemuLib/FdtNorFlashQemuLib.inf
|
||||
|
||||
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
|
||||
BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
|
||||
@ -124,8 +124,6 @@
|
||||
[BuildOptions]
|
||||
!if $(CAVIUM_ERRATUM_27456) == TRUE
|
||||
GCC:*_*_AARCH64_PP_FLAGS = -DCAVIUM_ERRATUM_27456
|
||||
!else
|
||||
GCC:*_*_AARCH64_CC_XIPFLAGS ==
|
||||
!endif
|
||||
|
||||
!include NetworkPkg/NetworkBuildOptions.dsc.inc
|
||||
@ -154,6 +152,9 @@
|
||||
gArmTokenSpaceGuid.PcdVFPEnabled|1
|
||||
!endif
|
||||
|
||||
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress|0x00000000
|
||||
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize|$(FD_SIZE)
|
||||
|
||||
gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000
|
||||
gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
|
||||
@ -233,6 +234,10 @@
|
||||
# System Memory Size -- 128 MB initially, actual size will be fetched from DT
|
||||
gArmTokenSpaceGuid.PcdSystemMemorySize|0x8000000
|
||||
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize | 0x40000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize | 0x40000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize | 0x40000
|
||||
|
||||
[PcdsFixedAtBuild.AARCH64]
|
||||
# Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry point,
|
||||
# if the entry point version is >= 3.0. AARCH64 OSes cannot assume the
|
||||
@ -245,6 +250,13 @@
|
||||
[PcdsDynamicDefault.common]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3
|
||||
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 | 0
|
||||
|
||||
## If TRUE, OvmfPkg/AcpiPlatformDxe will not wait for PCI
|
||||
# enumeration to complete before installing ACPI tables.
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE
|
||||
@ -295,6 +307,10 @@
|
||||
gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport|0x01
|
||||
gEfiNetworkPkgTokenSpaceGuid.PcdIPv6PXESupport|0x01
|
||||
|
||||
# whether to use HVC or SMC to issue monitor calls - this typically depends
|
||||
# on the exception level at which the UEFI system firmware executes
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
|
||||
|
||||
#
|
||||
# TPM2 support
|
||||
#
|
||||
@ -320,11 +336,7 @@
|
||||
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|5
|
||||
|
||||
[LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM]
|
||||
!if $(TPM2_ENABLE) == TRUE
|
||||
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
|
||||
!else
|
||||
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
|
||||
!endif
|
||||
|
||||
################################################################################
|
||||
#
|
||||
@ -341,11 +353,11 @@
|
||||
ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf
|
||||
ArmPkg/Drivers/CpuPei/CpuPei.inf
|
||||
|
||||
!if $(TPM2_ENABLE) == TRUE
|
||||
MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
|
||||
<LibraryClasses>
|
||||
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
|
||||
}
|
||||
!if $(TPM2_ENABLE) == TRUE
|
||||
MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf {
|
||||
<LibraryClasses>
|
||||
ResetSystemLib|ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVirtPsciResetSystemPeiLib.inf
|
||||
@ -406,7 +418,10 @@
|
||||
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
|
||||
!endif
|
||||
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
|
||||
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
|
||||
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf {
|
||||
<LibraryClasses>
|
||||
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
|
||||
}
|
||||
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
|
||||
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
|
||||
EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf {
|
||||
@ -434,6 +449,7 @@
|
||||
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
|
||||
}
|
||||
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
|
||||
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
|
||||
|
||||
#
|
||||
# Status Code Routing
|
||||
@ -556,6 +572,11 @@
|
||||
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
|
||||
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
|
||||
|
||||
#
|
||||
# Hash2 Protocol Support
|
||||
#
|
||||
SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
|
||||
|
||||
#
|
||||
# TPM2 support
|
||||
#
|
||||
|
@ -111,8 +111,8 @@ READ_LOCK_STATUS = TRUE
|
||||
INF ArmPkg/Drivers/CpuPei/CpuPei.inf
|
||||
INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
|
||||
|
||||
!if $(TPM2_ENABLE) == TRUE
|
||||
INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
|
||||
!if $(TPM2_ENABLE) == TRUE
|
||||
INF MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
|
||||
INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
|
||||
INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
|
||||
|
@ -75,6 +75,7 @@ READ_LOCK_STATUS = TRUE
|
||||
INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
|
||||
INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf
|
||||
INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
|
||||
INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
|
||||
|
||||
#
|
||||
# FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs
|
||||
@ -177,6 +178,11 @@ READ_LOCK_STATUS = TRUE
|
||||
INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
|
||||
INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
|
||||
|
||||
#
|
||||
# Hash2 Protocol producer
|
||||
#
|
||||
INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
|
||||
|
||||
#
|
||||
# TPM2 support
|
||||
#
|
||||
|
@ -46,10 +46,10 @@
|
||||
|
||||
!include NetworkPkg/NetworkDefines.dsc.inc
|
||||
|
||||
!include ArmVirtPkg/ArmVirt.dsc.inc
|
||||
|
||||
!include MdePkg/MdeLibs.dsc.inc
|
||||
|
||||
!include ArmVirtPkg/ArmVirt.dsc.inc
|
||||
|
||||
[LibraryClasses.common]
|
||||
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
|
||||
ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
|
||||
@ -57,7 +57,7 @@
|
||||
# Virtio Support
|
||||
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
|
||||
VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
|
||||
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf
|
||||
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgMmioDxeLib.inf
|
||||
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
|
||||
QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParserLib.inf
|
||||
QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf
|
||||
@ -65,7 +65,7 @@
|
||||
ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
|
||||
|
||||
TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
|
||||
VirtNorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
|
||||
VirtNorFlashPlatformLib|OvmfPkg/Library/FdtNorFlashQemuLib/FdtNorFlashQemuLib.inf
|
||||
|
||||
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
|
||||
BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
|
||||
@ -120,6 +120,8 @@
|
||||
gArmTokenSpaceGuid.PcdVFPEnabled|1
|
||||
!endif
|
||||
|
||||
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress|0x00000000
|
||||
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize|$(FD_SIZE)
|
||||
gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800
|
||||
@ -181,6 +183,10 @@
|
||||
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|3
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000
|
||||
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize | 0x40000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize | 0x40000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize | 0x40000
|
||||
|
||||
[PcdsPatchableInModule.common]
|
||||
# we need to provide a resolution for this PCD that supports PcdSet64()
|
||||
# being called from ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c,
|
||||
@ -203,9 +209,18 @@
|
||||
gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
|
||||
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
|
||||
|
||||
[PcdsDynamicDefault.common]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3
|
||||
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase | 0
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 | 0
|
||||
|
||||
## If TRUE, OvmfPkg/AcpiPlatformDxe will not wait for PCI
|
||||
# enumeration to complete before installing ACPI tables.
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE
|
||||
@ -311,7 +326,10 @@
|
||||
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
|
||||
!endif
|
||||
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
|
||||
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
|
||||
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf {
|
||||
<LibraryClasses>
|
||||
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
|
||||
}
|
||||
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
|
||||
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
|
||||
EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf {
|
||||
@ -339,6 +357,7 @@
|
||||
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
|
||||
}
|
||||
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
|
||||
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
|
||||
|
||||
#
|
||||
# Status Code Routing
|
||||
@ -461,6 +480,11 @@
|
||||
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
|
||||
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
|
||||
|
||||
#
|
||||
# Hash2 Protocol Support
|
||||
#
|
||||
SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
|
||||
|
||||
#
|
||||
# ACPI Support
|
||||
#
|
||||
|
@ -23,10 +23,10 @@
|
||||
SKUID_IDENTIFIER = DEFAULT
|
||||
FLASH_DEFINITION = ArmVirtPkg/ArmVirtXen.fdf
|
||||
|
||||
!include ArmVirtPkg/ArmVirt.dsc.inc
|
||||
|
||||
!include MdePkg/MdeLibs.dsc.inc
|
||||
|
||||
!include ArmVirtPkg/ArmVirt.dsc.inc
|
||||
|
||||
[LibraryClasses]
|
||||
SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
|
||||
!if $(TARGET) != RELEASE
|
||||
@ -120,6 +120,8 @@
|
||||
gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
|
||||
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
|
||||
|
||||
[PcdsDynamicDefault.common]
|
||||
|
||||
gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
|
||||
|
@ -1,42 +0,0 @@
|
||||
#/** @file
|
||||
#
|
||||
# Component description file for NorFlashQemuLib module
|
||||
#
|
||||
# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = NorFlashQemuLib
|
||||
FILE_GUID = 339B7829-4C5F-4EFC-B2DD-5050E530DECE
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = VirtNorFlashPlatformLib
|
||||
|
||||
[Sources.common]
|
||||
NorFlashQemuLib.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmVirtPkg/ArmVirtPkg.dec
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
OvmfPkg/OvmfPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
UefiBootServicesTableLib
|
||||
|
||||
[Protocols]
|
||||
gFdtClientProtocolGuid ## CONSUMES
|
||||
|
||||
[Depex]
|
||||
gFdtClientProtocolGuid
|
||||
|
||||
[Pcd]
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdFvSize
|
@ -18,6 +18,8 @@
|
||||
#include <Library/FdtSerialPortAddressLib.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include <Chipset/AArch64.h>
|
||||
|
||||
#include <Guid/EarlyPL011BaseAddress.h>
|
||||
#include <Guid/FdtHob.h>
|
||||
|
||||
@ -224,5 +226,17 @@ PlatformPeim (
|
||||
|
||||
BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));
|
||||
|
||||
#ifdef MDE_CPU_AARCH64
|
||||
//
|
||||
// Set the SMCCC conduit to SMC if executing at EL2, which is typically the
|
||||
// exception level that services HVCs rather than the one that invokes them.
|
||||
//
|
||||
if (ArmReadCurrentEL () == AARCH64_EL2) {
|
||||
Status = PcdSetBoolS (PcdMonitorConduitHvc, FALSE);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
[Pcd]
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdMonitorConduitHvc
|
||||
gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## SOMETIMES_PRODUCES
|
||||
gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
|
||||
|
||||
|
@ -240,6 +240,8 @@ class PlatformBuilder(UefiBuilder, BuildSettingsManager):
|
||||
args += " -serial stdio"
|
||||
# Mount disk with startup.nsh
|
||||
args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk"
|
||||
# Provides Rng services to the Guest VM
|
||||
args += " -device virtio-rng-pci"
|
||||
|
||||
# Conditional Args
|
||||
if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
|
||||
|
@ -8,7 +8,7 @@
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
INF_VERSION = 1.30
|
||||
BASE_NAME = ArmVirtPrePiUniCoreRelocatable
|
||||
FILE_GUID = f7d9fd14-9335-4389-80c5-334d6abfcced
|
||||
MODULE_TYPE = SEC
|
||||
|
@ -22,12 +22,6 @@
|
||||
|
||||
#include "PrePi.h"
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ProcessLibraryConstructorList (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
PrePiMain (
|
||||
IN UINTN UefiMemoryBase,
|
||||
|
@ -10,7 +10,7 @@
|
||||
##
|
||||
|
||||
[FD.QEMU_VARS]
|
||||
BaseAddress = 0x04000000
|
||||
BaseAddress = 0x00000000
|
||||
Size = 0xc0000
|
||||
ErasePolarity = 1
|
||||
BlockSize = 0x40000
|
||||
@ -18,7 +18,6 @@ NumBlocks = 3
|
||||
|
||||
|
||||
0x00000000|0x00040000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
|
||||
#NV_VARIABLE_STORE
|
||||
DATA = {
|
||||
## This is the EFI_FIRMWARE_VOLUME_HEADER
|
||||
@ -57,7 +56,6 @@ DATA = {
|
||||
|
||||
|
||||
0x00040000|0x00040000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
|
||||
#NV_FTW_WORKING
|
||||
DATA = {
|
||||
# EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = gEdkiiWorkingBlockSignatureGuid =
|
||||
@ -71,5 +69,4 @@ DATA = {
|
||||
}
|
||||
|
||||
0x00080000|0x00040000
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
|
||||
#NV_FTW_SPARE
|
||||
|
@ -128,10 +128,12 @@ InstallXenArmTables (
|
||||
EFI_ACPI_DESCRIPTION_HEADER *Xsdt;
|
||||
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *FadtTable;
|
||||
EFI_ACPI_DESCRIPTION_HEADER *DsdtTable;
|
||||
EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsTable;
|
||||
|
||||
XenAcpiRsdpStructurePtr = NULL;
|
||||
FadtTable = NULL;
|
||||
DsdtTable = NULL;
|
||||
FacsTable = NULL;
|
||||
TableHandle = 0;
|
||||
NumberOfTableEntries = 0;
|
||||
|
||||
@ -191,6 +193,8 @@ InstallXenArmTables (
|
||||
FadtTable = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *)
|
||||
(UINTN)CurrentTablePointer;
|
||||
DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)FadtTable->Dsdt;
|
||||
FacsTable = (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)
|
||||
(UINTN)FadtTable->FirmwareCtrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,14 +202,31 @@ InstallXenArmTables (
|
||||
//
|
||||
// Install DSDT table.
|
||||
//
|
||||
Status = AcpiProtocol->InstallAcpiTable (
|
||||
AcpiProtocol,
|
||||
DsdtTable,
|
||||
DsdtTable->Length,
|
||||
&TableHandle
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
if (DsdtTable != NULL) {
|
||||
Status = AcpiProtocol->InstallAcpiTable (
|
||||
AcpiProtocol,
|
||||
DsdtTable,
|
||||
DsdtTable->Length,
|
||||
&TableHandle
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Install FACS table.
|
||||
//
|
||||
if (FacsTable != NULL) {
|
||||
Status = AcpiProtocol->InstallAcpiTable (
|
||||
AcpiProtocol,
|
||||
FacsTable,
|
||||
FacsTable->Length,
|
||||
&TableHandle
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
@ -16,9 +16,9 @@
|
||||
"scope": "codeql-ext-dep",
|
||||
"type": "web",
|
||||
"name": "codeql_cli",
|
||||
"source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.12.4/codeql.zip",
|
||||
"version": "2.12.4",
|
||||
"sha256": "f682f1155d627ad97f10b1bcad97f682011986717bd3823e9cf831ed83ac96e7",
|
||||
"source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.17.3/codeql.zip",
|
||||
"version": "2.17.3",
|
||||
"sha256": "e5ac1d87ab38e405c9af5db234a338b10dffabc98a648903f1664dd2a566dfd5",
|
||||
"compression_type": "zip",
|
||||
"internal_path": "/codeql/",
|
||||
"flags": ["set_shell_var", ],
|
||||
|
@ -14,9 +14,9 @@
|
||||
"scope": "codeql-linux-ext-dep",
|
||||
"type": "web",
|
||||
"name": "codeql_linux_cli",
|
||||
"source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.14.5/codeql-linux64.zip",
|
||||
"version": "2.14.5",
|
||||
"sha256": "72aa5d748ff9ab57cfd86045560683bdc4897e0fe6d9f9a2786d9394674ae733",
|
||||
"source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.17.3/codeql-linux64.zip",
|
||||
"version": "2.17.3",
|
||||
"sha256": "9fba000c4b821534d354bc16821aa066fdb1304446226ea449870e64a8ad3c7a",
|
||||
"compression_type": "zip",
|
||||
"internal_path": "/codeql/",
|
||||
"flags": ["set_shell_var", ],
|
||||
|
@ -14,9 +14,9 @@
|
||||
"scope": "codeql-windows-ext-dep",
|
||||
"type": "web",
|
||||
"name": "codeql_windows_cli",
|
||||
"source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.14.5/codeql-win64.zip",
|
||||
"version": "2.14.5",
|
||||
"sha256": "861fcb38365cc311efee0c3a28c77494e93c69a969885b72e53173ad473f61aa",
|
||||
"source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.17.3/codeql-win64.zip",
|
||||
"version": "2.17.3",
|
||||
"sha256": "4c6fbf2ea2eaf0f47bf0347eacf54c6b9d6bdf7acb6b63e17f9e6f2dd83b34e7",
|
||||
"compression_type": "zip",
|
||||
"internal_path": "/codeql/",
|
||||
"flags": ["set_shell_var", ],
|
||||
|
@ -29,7 +29,7 @@ def Main():
|
||||
print ("ERROR: At least one argument is required!\n")
|
||||
PARSER.print_help()
|
||||
|
||||
today = datetime.datetime.utcnow()
|
||||
today = datetime.datetime.now(datetime.timezone.utc)
|
||||
if ARGS.year:
|
||||
ReversedNumber = str(today.year)[::-1]
|
||||
print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))
|
||||
|
@ -28,6 +28,7 @@ class Verbose:
|
||||
|
||||
class PatchCheckConf:
|
||||
ignore_change_id = False
|
||||
ignore_multi_package = False
|
||||
|
||||
class EmailAddressCheck:
|
||||
"""Checks an email address."""
|
||||
@ -85,7 +86,11 @@ class EmailAddressCheck:
|
||||
self.error("The email address cannot contain a space: " +
|
||||
mo.group(3))
|
||||
|
||||
if ' via Groups.Io' in name and mo.group(3).endswith('@groups.io'):
|
||||
if mo.group(3) == 'devel@edk2.groups.io':
|
||||
self.error("Email rewritten by lists DMARC / DKIM / SPF: " +
|
||||
email)
|
||||
|
||||
if ' via groups.io' in name.lower() and mo.group(3).endswith('@groups.io'):
|
||||
self.error("Email rewritten by lists DMARC / DKIM / SPF: " +
|
||||
email)
|
||||
|
||||
@ -94,6 +99,7 @@ class CommitMessageCheck:
|
||||
|
||||
def __init__(self, subject, message, author_email):
|
||||
self.ok = True
|
||||
self.ignore_multi_package = False
|
||||
|
||||
if subject is None and message is None:
|
||||
self.error('Commit message is missing!')
|
||||
@ -116,6 +122,7 @@ class CommitMessageCheck:
|
||||
self.check_overall_format()
|
||||
if not PatchCheckConf.ignore_change_id:
|
||||
self.check_change_id_format()
|
||||
self.check_ci_options_format()
|
||||
self.report_message_result()
|
||||
|
||||
url = 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format'
|
||||
@ -198,7 +205,7 @@ class CommitMessageCheck:
|
||||
if s[2] != ' ':
|
||||
self.error("There should be a space after '" + sig + ":'")
|
||||
|
||||
EmailAddressCheck(s[3], sig)
|
||||
self.ok &= EmailAddressCheck(s[3], sig).ok
|
||||
|
||||
return sigs
|
||||
|
||||
@ -225,8 +232,8 @@ class CommitMessageCheck:
|
||||
)
|
||||
|
||||
def check_misc_signatures(self):
|
||||
for sig in self.sig_types:
|
||||
self.find_signatures(sig)
|
||||
for sigtype in self.sig_types:
|
||||
sigs = self.find_signatures(sigtype)
|
||||
|
||||
cve_re = re.compile('CVE-[0-9]{4}-[0-9]{5}[^0-9]')
|
||||
|
||||
@ -318,6 +325,15 @@ class CommitMessageCheck:
|
||||
self.error('\"%s\" found in commit message:' % cid)
|
||||
return
|
||||
|
||||
def check_ci_options_format(self):
|
||||
cio='Continuous-integration-options:'
|
||||
for line in self.msg.splitlines():
|
||||
if not line.startswith(cio):
|
||||
continue
|
||||
options = line.split(':', 1)[1].split()
|
||||
if 'PatchCheck.ignore-multi-package' in options:
|
||||
self.ignore_multi_package = True
|
||||
|
||||
(START, PRE_PATCH, PATCH) = range(3)
|
||||
|
||||
class GitDiffCheck:
|
||||
@ -555,6 +571,7 @@ class CheckOnePatch:
|
||||
|
||||
msg_check = CommitMessageCheck(self.commit_subject, self.commit_msg, self.author_email)
|
||||
msg_ok = msg_check.ok
|
||||
self.ignore_multi_package = msg_check.ignore_multi_package
|
||||
|
||||
diff_ok = True
|
||||
if self.diff is not None:
|
||||
@ -665,6 +682,7 @@ class CheckGitCommits:
|
||||
"""
|
||||
|
||||
def __init__(self, rev_spec, max_count):
|
||||
dec_files = self.read_dec_files_from_git()
|
||||
commits = self.read_commit_list_from_git(rev_spec, max_count)
|
||||
if len(commits) == 1 and Verbose.level > Verbose.ONELINE:
|
||||
commits = [ rev_spec ]
|
||||
@ -680,10 +698,66 @@ class CheckGitCommits:
|
||||
email = self.read_committer_email_address_from_git(commit)
|
||||
self.ok &= EmailAddressCheck(email, 'Committer').ok
|
||||
patch = self.read_patch_from_git(commit)
|
||||
self.ok &= CheckOnePatch(commit, patch).ok
|
||||
check_patch = CheckOnePatch(commit, patch)
|
||||
self.ok &= check_patch.ok
|
||||
ignore_multi_package = check_patch.ignore_multi_package
|
||||
if PatchCheckConf.ignore_multi_package:
|
||||
ignore_multi_package = True
|
||||
prefix = 'WARNING: ' if ignore_multi_package else ''
|
||||
check_parent = self.check_parent_packages (dec_files, commit, prefix)
|
||||
if not ignore_multi_package:
|
||||
self.ok &= check_parent
|
||||
|
||||
if not commits:
|
||||
print("Couldn't find commit matching: '{}'".format(rev_spec))
|
||||
|
||||
def check_parent_packages(self, dec_files, commit, prefix):
|
||||
ok = True
|
||||
modified = self.get_parent_packages (dec_files, commit, 'AM')
|
||||
if len (modified) > 1:
|
||||
print("{}The commit adds/modifies files in multiple packages:".format(prefix))
|
||||
print(" *", '\n * '.join(modified))
|
||||
ok = False
|
||||
deleted = self.get_parent_packages (dec_files, commit, 'D')
|
||||
if len (deleted) > 1:
|
||||
print("{}The commit deletes files from multiple packages:".format(prefix))
|
||||
print(" *", '\n * '.join(deleted))
|
||||
ok = False
|
||||
return ok
|
||||
|
||||
def get_parent_packages(self, dec_files, commit, filter):
|
||||
filelist = self.read_files_modified_from_git (commit, filter)
|
||||
parents = set()
|
||||
for file in filelist:
|
||||
dec_found = False
|
||||
for dec_file in dec_files:
|
||||
if os.path.commonpath([dec_file, file]):
|
||||
dec_found = True
|
||||
parents.add(dec_file)
|
||||
if not dec_found and os.path.dirname (file):
|
||||
# No DEC file found and file is in a subdir
|
||||
# Covers BaseTools, .github, .azurepipelines, .pytool
|
||||
parents.add(file.split('/')[0])
|
||||
return list(parents)
|
||||
|
||||
def read_dec_files_from_git(self):
|
||||
# run git ls-files *.dec
|
||||
out = self.run_git('ls-files', '*.dec')
|
||||
# return list of .dec files
|
||||
try:
|
||||
return out.split()
|
||||
except:
|
||||
return []
|
||||
|
||||
def read_files_modified_from_git(self, commit, filter):
|
||||
# run git diff-tree --no-commit-id --name-only -r <commit>
|
||||
out = self.run_git('diff-tree', '--no-commit-id', '--name-only',
|
||||
'--diff-filter=' + filter, '-r', commit)
|
||||
try:
|
||||
return out.split()
|
||||
except:
|
||||
return []
|
||||
|
||||
def read_commit_list_from_git(self, rev_spec, max_count):
|
||||
# Run git to get the commit patch
|
||||
cmd = [ 'rev-list', '--abbrev-commit', '--no-walk' ]
|
||||
@ -794,6 +868,9 @@ class PatchCheckApp:
|
||||
group.add_argument("--ignore-change-id",
|
||||
action="store_true",
|
||||
help="Ignore the presence of 'Change-Id:' tags in commit message")
|
||||
group.add_argument("--ignore-multi-package",
|
||||
action="store_true",
|
||||
help="Ignore if commit modifies files in multiple packages")
|
||||
self.args = parser.parse_args()
|
||||
if self.args.oneline:
|
||||
Verbose.level = Verbose.ONELINE
|
||||
@ -801,6 +878,8 @@ class PatchCheckApp:
|
||||
Verbose.level = Verbose.SILENT
|
||||
if self.args.ignore_change_id:
|
||||
PatchCheckConf.ignore_change_id = True
|
||||
if self.args.ignore_multi_package:
|
||||
PatchCheckConf.ignore_multi_package = True
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(PatchCheckApp().retval)
|
||||
|
@ -1556,7 +1556,17 @@ typedef enum {
|
||||
EfiKeyF12,
|
||||
EfiKeyPrint,
|
||||
EfiKeySLck,
|
||||
EfiKeyPause
|
||||
EfiKeyPause,
|
||||
EfiKeyIntl0,
|
||||
EfiKeyIntl1,
|
||||
EfiKeyIntl2,
|
||||
EfiKeyIntl3,
|
||||
EfiKeyIntl4,
|
||||
EfiKeyIntl5,
|
||||
EfiKeyIntl6,
|
||||
EfiKeyIntl7,
|
||||
EfiKeyIntl8,
|
||||
EfiKeyIntl9
|
||||
} EFI_KEY;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1371,6 +1371,14 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
|
||||
else:
|
||||
if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC, SUP_MODULE_USER_DEFINED, SUP_MODULE_HOST_APPLICATION]:
|
||||
AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))
|
||||
if Info.ModuleType == SUP_MODULE_SEC and Info.AutoGenVersion >= 0x0001001E:
|
||||
AutoGenH.Append(("\n"
|
||||
"// ProcessLibraryConstructorList() declared here because SEC has no standard entry point.\n"
|
||||
"VOID\n"
|
||||
"EFIAPI\n"
|
||||
"ProcessLibraryConstructorList (\n"
|
||||
" VOID\n"
|
||||
" );\n"))
|
||||
elif Info.ModuleType in SUP_MODULE_SET_PEI:
|
||||
AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
|
||||
elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,
|
||||
|
@ -37,7 +37,7 @@ parser.add_argument("-l", "--LayoutFileName", dest="LayoutFileName", nargs='+',
|
||||
the file will be generated with default name (Layout_'InputFileName'.txt). \
|
||||
Currently supports two formats: json, txt. More formats will be added in the future")
|
||||
parser.add_argument("-c", "--ConfigFilePath", dest="ConfigFilePath", nargs='+',
|
||||
help="Provide the target FmmtConf.ini file path: '-c C:\Code\FmmtConf.ini' \
|
||||
help="Provide the target FmmtConf.ini file path: '-c C:\\Code\\FmmtConf.ini' \
|
||||
FmmtConf file saves the target guidtool used in compress/uncompress process.\
|
||||
If do not provide, FMMT tool will search the inputfile folder for FmmtConf.ini firstly, if not found,\
|
||||
the FmmtConf.ini saved in FMMT tool's folder will be used as default.")
|
||||
|
@ -1,6 +1,7 @@
|
||||
## @file
|
||||
# generate capsule
|
||||
#
|
||||
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
|
||||
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
@ -78,6 +79,8 @@ class Capsule (CapsuleClassObject):
|
||||
Flags |= 0x00010000
|
||||
elif flag == 'InitiateReset':
|
||||
Flags |= 0x00040000
|
||||
if 'OEM_CAPSULE_FLAGS' in self.TokensDict:
|
||||
Flags |= int(self.TokensDict['OEM_CAPSULE_FLAGS'],16)
|
||||
Header.write(pack('=I', Flags))
|
||||
#
|
||||
# typedef struct {
|
||||
|
@ -19,6 +19,7 @@ from .GenFdsGlobalVariable import GenFdsGlobalVariable
|
||||
from .Ffs import SectionSuffix,FdfFvFileTypeToFileType
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from . import Section
|
||||
from . import RuleSimpleFile
|
||||
from . import RuleComplexFile
|
||||
@ -92,7 +93,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
||||
|
||||
if ModuleType != SUP_MODULE_USER_DEFINED and ModuleType != SUP_MODULE_HOST_APPLICATION:
|
||||
for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys():
|
||||
if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:
|
||||
if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit() and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:
|
||||
self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]
|
||||
|
||||
StrModule = str(self.InfModule)
|
||||
@ -100,7 +101,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
||||
if StrModule in PlatformDataBase.Modules:
|
||||
PlatformModule = PlatformDataBase.Modules[StrModule]
|
||||
for LibraryClass in PlatformModule.LibraryClasses:
|
||||
if LibraryClass.startswith("NULL"):
|
||||
if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit():
|
||||
self.InfModule.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]
|
||||
|
||||
DependencyList = [self.InfModule]
|
||||
@ -156,7 +157,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
||||
if len(self.InfFileName) > 1 and self.InfFileName[0] == '\\' and self.InfFileName[1] == '\\':
|
||||
pass
|
||||
elif self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :
|
||||
self.InfFileName = self.InfFileName[1:]
|
||||
ws_path = Path(GenFdsGlobalVariable.WorkSpaceDir)
|
||||
inf_path = Path(self.InfFileName)
|
||||
if ws_path in inf_path.parents:
|
||||
self.InfFileName = str(inf_path.relative_to(ws_path))
|
||||
else:
|
||||
self.InfFileName = self.InfFileName[1:]
|
||||
|
||||
if self.InfFileName.find('$') == -1:
|
||||
InfPath = NormPath(self.InfFileName)
|
||||
|
@ -3033,7 +3033,7 @@ class DscBuildData(PlatformBuildClassObject):
|
||||
StructuredPcdsData["OBJECTS"][include_file] = os.path.getmtime(include_file)
|
||||
MakeApp += "$(OBJECTS) : %s\n" % include_file
|
||||
if sys.platform == "win32":
|
||||
PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c"))
|
||||
PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source\\C\\Common\\PcdValueCommon.c"))
|
||||
MakeApp = MakeApp + '%s\\PcdValueCommon.c : %s\n' % (self.OutputPath, PcdValueCommonPath)
|
||||
MakeApp = MakeApp + '\tcopy /y %s $@\n' % (PcdValueCommonPath)
|
||||
else:
|
||||
|
@ -102,12 +102,12 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
|
||||
#
|
||||
if Module.ModuleType != SUP_MODULE_USER_DEFINED:
|
||||
for LibraryClass in Platform.LibraryClasses.GetKeys():
|
||||
if LibraryClass.startswith("NULL") and Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
|
||||
if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit() and Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
|
||||
Module.LibraryClasses[LibraryClass] = Platform.LibraryClasses[LibraryClass, Module.ModuleType]
|
||||
|
||||
# add forced library instances (specified in module overrides)
|
||||
for LibraryClass in Platform.Modules[str(Module)].LibraryClasses:
|
||||
if LibraryClass.startswith("NULL"):
|
||||
if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit():
|
||||
Module.LibraryClasses[LibraryClass] = Platform.Modules[str(Module)].LibraryClasses[LibraryClass]
|
||||
|
||||
# EdkII module
|
||||
@ -123,6 +123,8 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
|
||||
while len(LibraryConsumerList) > 0:
|
||||
M = LibraryConsumerList.pop()
|
||||
for LibraryClassName in M.LibraryClasses:
|
||||
if LibraryClassName.startswith("NULL") and LibraryClassName[4:].isdigit() and bool(M.LibraryClass):
|
||||
continue
|
||||
if LibraryClassName not in LibraryInstance:
|
||||
# override library instance for this module
|
||||
LibraryPath = Platform.Modules[str(Module)].LibraryClasses.get(LibraryClassName,Platform.LibraryClasses[LibraryClassName, ModuleType])
|
||||
@ -139,7 +141,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
|
||||
|
||||
LibraryModule = BuildDatabase[LibraryPath, Arch, Target, Toolchain]
|
||||
# for those forced library instance (NULL library), add a fake library class
|
||||
if LibraryClassName.startswith("NULL"):
|
||||
if LibraryClassName.startswith("NULL") and LibraryClassName[4:].isdigit():
|
||||
LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))
|
||||
elif LibraryModule.LibraryClass is None \
|
||||
or len(LibraryModule.LibraryClass) == 0 \
|
||||
|
@ -88,6 +88,7 @@
|
||||
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
|
||||
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
|
||||
MbedTlsLib|CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf
|
||||
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
|
||||
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
|
||||
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
|
||||
|
||||
|
@ -3589,6 +3589,131 @@ CryptoServicePkcs1v2Encrypt (
|
||||
return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs1v2Encrypt, Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CryptoServiceRsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
return CALL_BASECRYPTLIB (Rsa.Services.RsaOaepEncrypt, RsaOaepEncrypt, (RsaContext, InData, InDataSize, PrngSeed, PrngSeedSize, DigestLen, EncryptedData, EncryptedDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CryptoServicePkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs1v2Decrypt, Pkcs1v2Decrypt, (PrivateKey, PrivateKeySize, EncryptedData, EncryptedDataSize, OutData, OutDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CryptoServiceRsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
return CALL_BASECRYPTLIB (Rsa.Services.RsaOaepDecrypt, RsaOaepDecrypt, (RsaContext, EncryptedData, EncryptedDataSize, DigestLen, OutData, OutDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
|
||||
Cryptographic Message Syntax Standard". The input signed data could be wrapped
|
||||
@ -6987,5 +7112,8 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = {
|
||||
CryptoServiceX509VerifyCertChain,
|
||||
CryptoServiceX509GetCertFromCertChain,
|
||||
CryptoServiceAsn1GetTag,
|
||||
CryptoServiceX509GetExtendedBasicConstraints
|
||||
CryptoServiceX509GetExtendedBasicConstraints,
|
||||
CryptoServicePkcs1v2Decrypt,
|
||||
CryptoServiceRsaOaepEncrypt,
|
||||
CryptoServiceRsaOaepDecrypt,
|
||||
};
|
||||
|
@ -5,6 +5,7 @@
|
||||
functionality enabling.
|
||||
|
||||
Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
@ -2147,6 +2148,122 @@ Pkcs1v2Encrypt (
|
||||
OUT UINTN *EncryptedDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
The 3rd parameter of Pkcs7GetSigners will return all embedded
|
||||
X.509 certificate in one given PKCS7 signature. The format is:
|
||||
@ -2234,6 +2351,8 @@ Pkcs7FreeSigners (
|
||||
unchained to the signer's certificates.
|
||||
The input signed data could be wrapped in a ContentInfo structure.
|
||||
|
||||
Pkcs7GetCertificatesList has not been implemented in BaseCryptoLibMbedTls.
|
||||
|
||||
@param[in] P7Data Pointer to the PKCS#7 message.
|
||||
@param[in] P7Length Length of the PKCS#7 message in bytes.
|
||||
@param[out] SignerChainCerts Pointer to the certificates list chained to signer's
|
||||
@ -3022,6 +3141,8 @@ DhComputeKey (
|
||||
If Seed is NULL, then default seed is used.
|
||||
If this interface is not supported, then return FALSE.
|
||||
|
||||
RandomSeed has not been implemented in BaseCryptoLibMbedTls.
|
||||
|
||||
@param[in] Seed Pointer to seed value.
|
||||
If NULL, default seed is used.
|
||||
@param[in] SeedSize Size of seed value.
|
||||
|
@ -23,6 +23,7 @@
|
||||
* Sha1 family
|
||||
|
||||
Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
@ -124,6 +125,7 @@ typedef struct {
|
||||
UINT8 Pkcs7GetCertificatesList : 1;
|
||||
UINT8 AuthenticodeVerify : 1;
|
||||
UINT8 ImageTimestampVerify : 1;
|
||||
UINT8 Pkcs1v2Decrypt : 1;
|
||||
} Services;
|
||||
UINT32 Family;
|
||||
} Pkcs;
|
||||
@ -158,6 +160,8 @@ typedef struct {
|
||||
UINT8 Pkcs1Verify : 1;
|
||||
UINT8 GetPrivateKeyFromPem : 1;
|
||||
UINT8 GetPublicKeyFromX509 : 1;
|
||||
UINT8 RsaOaepEncrypt : 1;
|
||||
UINT8 RsaOaepDecrypt : 1;
|
||||
} Services;
|
||||
UINT32 Family;
|
||||
} Rsa;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
Copyright (C) 2016 Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (C) Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
||||
|
||||
**/
|
||||
@ -14,6 +14,37 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
|
||||
/**
|
||||
Retrieve a pointer to EVP message digest object.
|
||||
|
||||
@param[in] DigestLen Length of the message digest.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
const
|
||||
EVP_MD *
|
||||
GetEvpMD (
|
||||
IN UINT16 DigestLen
|
||||
)
|
||||
{
|
||||
switch (DigestLen) {
|
||||
case SHA1_DIGEST_SIZE:
|
||||
return EVP_sha1 ();
|
||||
break;
|
||||
case SHA256_DIGEST_SIZE:
|
||||
return EVP_sha256 ();
|
||||
break;
|
||||
case SHA384_DIGEST_SIZE:
|
||||
return EVP_sha384 ();
|
||||
break;
|
||||
case SHA512_DIGEST_SIZE:
|
||||
return EVP_sha512 ();
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
@ -26,15 +57,20 @@
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] PublicKey A pointer to the DER-encoded X509 certificate that
|
||||
@param[in] Pkey A pointer to an EVP_PKEY struct that
|
||||
will be used to encrypt the data.
|
||||
@param[in] PublicKeySize Size of the X509 cert buffer.
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
@ -45,50 +81,35 @@
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Encrypt (
|
||||
IN CONST UINT8 *PublicKey,
|
||||
IN UINTN PublicKeySize,
|
||||
InternalPkcs1v2Encrypt (
|
||||
EVP_PKEY *Pkey,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
CONST UINT8 *TempPointer;
|
||||
X509 *CertData;
|
||||
EVP_PKEY *InternalPublicKey;
|
||||
EVP_PKEY_CTX *PkeyCtx;
|
||||
UINT8 *OutData;
|
||||
UINTN OutDataSize;
|
||||
CONST EVP_MD *HashAlg;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((PublicKey == NULL) || (InData == NULL) ||
|
||||
if ((Pkey == NULL) || (InData == NULL) ||
|
||||
(EncryptedData == NULL) || (EncryptedDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check public key size.
|
||||
//
|
||||
if (PublicKeySize > 0xFFFFFFFF) {
|
||||
//
|
||||
// Public key size is too large for implementation.
|
||||
//
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*EncryptedData = NULL;
|
||||
*EncryptedDataSize = 0;
|
||||
Result = FALSE;
|
||||
TempPointer = NULL;
|
||||
CertData = NULL;
|
||||
InternalPublicKey = NULL;
|
||||
PkeyCtx = NULL;
|
||||
OutData = NULL;
|
||||
OutDataSize = 0;
|
||||
@ -104,34 +125,10 @@ Pkcs1v2Encrypt (
|
||||
RandomSeed (NULL, 0);
|
||||
}
|
||||
|
||||
//
|
||||
// Parse the X509 cert and extract the public key.
|
||||
//
|
||||
TempPointer = PublicKey;
|
||||
CertData = d2i_X509 (&CertData, &TempPointer, (UINT32)PublicKeySize);
|
||||
if (CertData == NULL) {
|
||||
//
|
||||
// Fail to parse X509 cert.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract the public key from the x509 cert in a format that
|
||||
// OpenSSL can use.
|
||||
//
|
||||
InternalPublicKey = X509_get_pubkey (CertData);
|
||||
if (InternalPublicKey == NULL) {
|
||||
//
|
||||
// Fail to extract public key.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a context for the public key operation.
|
||||
//
|
||||
PkeyCtx = EVP_PKEY_CTX_new (InternalPublicKey, NULL);
|
||||
PkeyCtx = EVP_PKEY_CTX_new (Pkey, NULL);
|
||||
if (PkeyCtx == NULL) {
|
||||
//
|
||||
// Fail to create contex.
|
||||
@ -151,6 +148,21 @@ Pkcs1v2Encrypt (
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (DigestLen != 0) {
|
||||
HashAlg = GetEvpMD (DigestLen);
|
||||
if (HashAlg == NULL) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_CTX_set_rsa_oaep_md (PkeyCtx, HashAlg) <= 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_CTX_set_rsa_mgf1_md (PkeyCtx, HashAlg) <= 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Determine the required buffer length for malloc'ing.
|
||||
//
|
||||
@ -196,17 +208,507 @@ _Exit:
|
||||
//
|
||||
// Release Resources
|
||||
//
|
||||
if (CertData != NULL) {
|
||||
X509_free (CertData);
|
||||
}
|
||||
|
||||
if (InternalPublicKey != NULL) {
|
||||
EVP_PKEY_free (InternalPublicKey);
|
||||
}
|
||||
|
||||
if (PkeyCtx != NULL) {
|
||||
EVP_PKEY_CTX_free (PkeyCtx);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to parse X509 certificate.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] PublicKey A pointer to the DER-encoded X509 certificate that
|
||||
will be used to encrypt the data.
|
||||
@param[in] PublicKeySize Size of the X509 cert buffer.
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Encrypt (
|
||||
IN CONST UINT8 *PublicKey,
|
||||
IN UINTN PublicKeySize,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
CONST UINT8 *TempPointer;
|
||||
X509 *CertData;
|
||||
EVP_PKEY *Pkey;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((PublicKey == NULL) || (InData == NULL) ||
|
||||
(EncryptedData == NULL) || (EncryptedDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check public key size.
|
||||
//
|
||||
if (PublicKeySize > 0xFFFFFFFF) {
|
||||
//
|
||||
// Public key size is too large for implementation.
|
||||
//
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*EncryptedData = NULL;
|
||||
*EncryptedDataSize = 0;
|
||||
Result = FALSE;
|
||||
TempPointer = NULL;
|
||||
CertData = NULL;
|
||||
Pkey = NULL;
|
||||
|
||||
//
|
||||
// Parse the X509 cert and extract the public key.
|
||||
//
|
||||
TempPointer = PublicKey;
|
||||
CertData = d2i_X509 (&CertData, &TempPointer, (UINT32)PublicKeySize);
|
||||
if (CertData == NULL) {
|
||||
//
|
||||
// Fail to parse X509 cert.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract the public key from the x509 cert in a format that
|
||||
// OpenSSL can use.
|
||||
//
|
||||
Pkey = X509_get_pubkey (CertData);
|
||||
if (Pkey == NULL) {
|
||||
//
|
||||
// Fail to extract public key.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Result = InternalPkcs1v2Encrypt (Pkey, InData, InDataSize, PrngSeed, PrngSeedSize, 0, EncryptedData, EncryptedDataSize);
|
||||
|
||||
_Exit:
|
||||
//
|
||||
// Release Resources
|
||||
//
|
||||
if (CertData != NULL) {
|
||||
X509_free (CertData);
|
||||
}
|
||||
|
||||
if (Pkey != NULL) {
|
||||
EVP_PKEY_free (Pkey);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
EVP_PKEY *Pkey;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if (((RsaContext == NULL) || (InData == NULL)) ||
|
||||
(EncryptedData == NULL) || (EncryptedDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*EncryptedData = NULL;
|
||||
*EncryptedDataSize = 0;
|
||||
Result = FALSE;
|
||||
Pkey = NULL;
|
||||
|
||||
Pkey = EVP_PKEY_new ();
|
||||
if (Pkey == NULL) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_set1_RSA (Pkey, (RSA *)RsaContext) == 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Result = InternalPkcs1v2Encrypt (Pkey, InData, InDataSize, PrngSeed, PrngSeedSize, DigestLen, EncryptedData, EncryptedDataSize);
|
||||
|
||||
_Exit:
|
||||
//
|
||||
// Release Resources
|
||||
//
|
||||
if (Pkey != NULL) {
|
||||
EVP_PKEY_free (Pkey);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] Pkey A pointer to an EVP_PKEY which will decrypt that data.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
InternalPkcs1v2Decrypt (
|
||||
EVP_PKEY *Pkey,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
EVP_PKEY_CTX *PkeyCtx;
|
||||
UINT8 *TempData;
|
||||
UINTN TempDataSize;
|
||||
INTN ReturnCode;
|
||||
CONST EVP_MD *HashAlg;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((Pkey == NULL) || (EncryptedData == NULL) ||
|
||||
(OutData == NULL) || (OutDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Result = FALSE;
|
||||
PkeyCtx = NULL;
|
||||
TempData = NULL;
|
||||
TempDataSize = 0;
|
||||
|
||||
//
|
||||
// Create a context for the decryption operation.
|
||||
//
|
||||
PkeyCtx = EVP_PKEY_CTX_new (Pkey, NULL);
|
||||
if (PkeyCtx == NULL) {
|
||||
//
|
||||
// Fail to create contex.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "[%a] EVP_PKEY_CTK_new() failed\n", __func__));
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the context and set the desired padding.
|
||||
//
|
||||
if ((EVP_PKEY_decrypt_init (PkeyCtx) <= 0) ||
|
||||
(EVP_PKEY_CTX_set_rsa_padding (PkeyCtx, RSA_PKCS1_OAEP_PADDING) <= 0))
|
||||
{
|
||||
//
|
||||
// Fail to initialize the context.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "[%a] EVP_PKEY_decrypt_init() failed\n", __func__));
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (DigestLen != 0) {
|
||||
HashAlg = GetEvpMD (DigestLen);
|
||||
if (HashAlg == NULL) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_CTX_set_rsa_oaep_md (PkeyCtx, HashAlg) <= 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_CTX_set_rsa_mgf1_md (PkeyCtx, HashAlg) <= 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Determine the required buffer length for malloc'ing.
|
||||
//
|
||||
ReturnCode = EVP_PKEY_decrypt (PkeyCtx, NULL, &TempDataSize, EncryptedData, EncryptedDataSize);
|
||||
if (ReturnCode <= 0) {
|
||||
//
|
||||
// Fail to determine output buffer size.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "[%a] EVP_PKEY_decrypt() failed to determine output buffer size (rc=%d)\n", __func__, ReturnCode));
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate a buffer for the output data.
|
||||
//
|
||||
TempData = AllocatePool (TempDataSize);
|
||||
if (TempData == NULL) {
|
||||
//
|
||||
// Fail to allocate the output buffer.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Decrypt Data.
|
||||
//
|
||||
ReturnCode = EVP_PKEY_decrypt (PkeyCtx, TempData, &TempDataSize, EncryptedData, EncryptedDataSize);
|
||||
if (ReturnCode <= 0) {
|
||||
//
|
||||
// Fail to decrypt data, need to free the output buffer.
|
||||
//
|
||||
FreePool (TempData);
|
||||
TempData = NULL;
|
||||
TempDataSize = 0;
|
||||
|
||||
DEBUG ((DEBUG_ERROR, "[%a] EVP_PKEY_decrypt(TempData) failed to decrypt (rc=%d)\n", __func__, ReturnCode));
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Decrypt done.
|
||||
//
|
||||
*OutData = TempData;
|
||||
*OutDataSize = TempDataSize;
|
||||
Result = TRUE;
|
||||
|
||||
_Exit:
|
||||
if (PkeyCtx != NULL) {
|
||||
EVP_PKEY_CTX_free (PkeyCtx);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
EVP_PKEY *Pkey;
|
||||
CONST UINT8 *TempPointer;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((PrivateKey == NULL) || (EncryptedData == NULL) ||
|
||||
(OutData == NULL) || (OutDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Result = FALSE;
|
||||
Pkey = NULL;
|
||||
TempPointer = NULL;
|
||||
|
||||
//
|
||||
// Parse the private key.
|
||||
//
|
||||
TempPointer = PrivateKey;
|
||||
Pkey = d2i_PrivateKey (EVP_PKEY_RSA, &Pkey, &TempPointer, (UINT32)PrivateKeySize);
|
||||
if (Pkey == NULL) {
|
||||
//
|
||||
// Fail to parse private key.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "[%a] d2i_PrivateKey() failed\n", __func__));
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Result = InternalPkcs1v2Decrypt (Pkey, EncryptedData, EncryptedDataSize, 0, OutData, OutDataSize);
|
||||
|
||||
_Exit:
|
||||
if (Pkey != NULL) {
|
||||
EVP_PKEY_free (Pkey);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
EVP_PKEY *Pkey;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((RsaContext == NULL) || (EncryptedData == NULL) ||
|
||||
(OutData == NULL) || (OutDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Result = FALSE;
|
||||
Pkey = NULL;
|
||||
|
||||
//
|
||||
// Create a context for the decryption operation.
|
||||
//
|
||||
|
||||
Pkey = EVP_PKEY_new ();
|
||||
if (Pkey == NULL) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_set1_RSA (Pkey, (RSA *)RsaContext) == 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Result = InternalPkcs1v2Decrypt (Pkey, EncryptedData, EncryptedDataSize, DigestLen, OutData, OutDataSize);
|
||||
|
||||
_Exit:
|
||||
if (Pkey != NULL) {
|
||||
EVP_PKEY_free (Pkey);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
Copyright (C) 2016 Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (C) Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
||||
|
||||
**/
|
||||
@ -48,3 +48,131 @@ Pkcs1v2Encrypt (
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -839,17 +839,17 @@ X509GetTBSCert (
|
||||
Length = 0;
|
||||
Inf = ASN1_get_object (&Temp, (long *)&Length, (int *)&Asn1Tag, (int *)&ObjClass, (long)CertSize);
|
||||
|
||||
if (((Inf & 0x80) == 0x00) && (Asn1Tag != V_ASN1_SEQUENCE)) {
|
||||
if (((Inf & 0x80) == 0x80) || (Asn1Tag != V_ASN1_SEQUENCE)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*TBSCert = (UINT8 *)Temp;
|
||||
|
||||
ASN1_get_object (&Temp, (long *)&Length, (int *)&Asn1Tag, (int *)&ObjClass, (long)Length);
|
||||
Inf = ASN1_get_object (&Temp, (long *)&Length, (int *)&Asn1Tag, (int *)&ObjClass, (long)Length);
|
||||
//
|
||||
// Verify the parsed TBSCertificate is one correct SEQUENCE data.
|
||||
//
|
||||
if (((Inf & 0x80) == 0x00) && (Asn1Tag != V_ASN1_SEQUENCE)) {
|
||||
if (((Inf & 0x80) == 0x80) || (Asn1Tag != V_ASN1_SEQUENCE)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -42,14 +42,6 @@ RandomSeed (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// The software PRNG implementation built in OpenSSL depends on message digest algorithm.
|
||||
// Make sure SHA-1 digest algorithm is available here.
|
||||
//
|
||||
if (EVP_add_digest (EVP_sha1 ()) == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Seed the pseudorandom number generator with user-supplied value.
|
||||
// NOTE: A cryptographic PRNG must be seeded with unpredictable data.
|
||||
|
@ -40,14 +40,6 @@ RandomSeed (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// The software PRNG implementation built in OpenSSL depends on message digest algorithm.
|
||||
// Make sure SHA-1 digest algorithm is available here.
|
||||
//
|
||||
if (EVP_add_digest (EVP_sha1 ()) == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Seed the pseudorandom number generator with user-supplied value.
|
||||
// NOTE: A cryptographic PRNG must be seeded with unpredictable data.
|
||||
|
@ -48,10 +48,10 @@
|
||||
Cipher/CryptAes.c
|
||||
Cipher/CryptAeadAesGcmNull.c
|
||||
Pk/CryptRsaBasic.c
|
||||
Pk/CryptRsaExtNull.c
|
||||
Pk/CryptRsaExt.c
|
||||
Pk/CryptPkcs1Oaep.c
|
||||
Pk/CryptPkcs5Pbkdf2.c
|
||||
Pk/CryptPkcs7SignNull.c
|
||||
Pk/CryptPkcs7Sign.c
|
||||
Pk/CryptPkcs7VerifyCommon.c
|
||||
Pk/CryptPkcs7VerifyBase.c
|
||||
Pk/CryptPkcs7VerifyEku.c
|
||||
@ -63,7 +63,7 @@
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pem/CryptPem.c
|
||||
Bn/CryptBnNull.c
|
||||
Bn/CryptBn.c
|
||||
|
||||
SysCall/CrtWrapper.c
|
||||
SysCall/ConstantTimeClock.c
|
||||
|
@ -27,34 +27,38 @@
|
||||
|
||||
[Sources]
|
||||
InternalCryptLib.h
|
||||
Cipher/CryptAeadAesGcmNull.c
|
||||
Cipher/CryptAes.c
|
||||
Hash/CryptMd5.c
|
||||
Hash/CryptSha1.c
|
||||
Hash/CryptSha256.c
|
||||
Hash/CryptSha512.c
|
||||
Hash/CryptParallelHashNull.c
|
||||
Hash/CryptSm3Null.c
|
||||
Hash/CryptMd5.c
|
||||
Hash/CryptSha1.c
|
||||
Hash/CryptSm3.c
|
||||
Hmac/CryptHmac.c
|
||||
Kdf/CryptHkdf.c
|
||||
Cipher/CryptAes.c
|
||||
Cipher/CryptAeadAesGcm.c
|
||||
Pk/CryptRsaBasic.c
|
||||
Pk/CryptRsaExtNull.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Bn/CryptBnNull.c
|
||||
Pem/CryptPemNull.c
|
||||
Pk/CryptRsaExt.c
|
||||
Pk/CryptPkcs1Oaep.c
|
||||
Pk/CryptPkcs5Pbkdf2.c
|
||||
Pk/CryptPkcs7Sign.c
|
||||
Pk/CryptPkcs7VerifyCommon.c
|
||||
Pk/CryptPkcs7VerifyBase.c
|
||||
Pk/CryptPkcs7VerifyEku.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptX509.c
|
||||
Pk/CryptAuthenticode.c
|
||||
Pk/CryptTs.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSign.c
|
||||
Pk/CryptEcNull.c
|
||||
Pk/CryptPkcs1OaepNull.c
|
||||
Pk/CryptPkcs5Pbkdf2Null.c
|
||||
Pk/CryptPkcs7SignNull.c
|
||||
Pk/CryptPkcs7VerifyNull.c
|
||||
Pk/CryptPkcs7VerifyEkuNull.c
|
||||
Pk/CryptX509Null.c
|
||||
Pk/CryptAuthenticodeNull.c
|
||||
Pk/CryptTsNull.c
|
||||
Rand/CryptRandNull.c
|
||||
Pem/CryptPem.c
|
||||
Bn/CryptBnNull.c
|
||||
Rand/CryptRand.c
|
||||
|
||||
SysCall/CrtWrapper.c
|
||||
SysCall/DummyOpensslSupport.c
|
||||
SysCall/BaseMemAllocation.c
|
||||
SysCall/TimerWrapper.c
|
||||
|
||||
[Packages]
|
||||
@ -68,6 +72,7 @@
|
||||
UefiRuntimeServicesTableLib
|
||||
DebugLib
|
||||
MbedTlsLib
|
||||
OpensslLib
|
||||
PrintLib
|
||||
IntrinsicLib
|
||||
RngLib
|
||||
|
227
CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAeadAesGcm.c
Normal file
227
CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAeadAesGcm.c
Normal file
@ -0,0 +1,227 @@
|
||||
/** @file
|
||||
AEAD (AES-GCM) Wrapper Implementation over MbedTLS.
|
||||
|
||||
RFC 5116 - An Interface and Algorithms for Authenticated Encryption
|
||||
NIST SP800-38d - Cipher Modes of Operation: Galois / Counter Mode(GCM) and GMAC
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/gcm.h>
|
||||
|
||||
/**
|
||||
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
|
||||
AeadAesGcmEncrypt (
|
||||
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
|
||||
)
|
||||
{
|
||||
mbedtls_gcm_context Ctx;
|
||||
INT32 Ret;
|
||||
|
||||
if (DataInSize > INT_MAX) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ADataSize > INT_MAX) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (IvSize != 12) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch (KeySize) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((TagSize != 12) && (TagSize != 13) && (TagSize != 14) && (TagSize != 15) && (TagSize != 16)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (DataOutSize != NULL) {
|
||||
if ((*DataOutSize > INT_MAX) || (*DataOutSize < DataInSize)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_gcm_init (&Ctx);
|
||||
|
||||
Ret = mbedtls_gcm_setkey (&Ctx, MBEDTLS_CIPHER_ID_AES, Key, (UINT32)(KeySize * 8));
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_gcm_crypt_and_tag (
|
||||
&Ctx,
|
||||
MBEDTLS_GCM_ENCRYPT,
|
||||
(UINT32)DataInSize,
|
||||
Iv,
|
||||
(UINT32)IvSize,
|
||||
AData,
|
||||
(UINT32)ADataSize,
|
||||
DataIn,
|
||||
DataOut,
|
||||
TagSize,
|
||||
TagOut
|
||||
);
|
||||
mbedtls_gcm_free (&Ctx);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (DataOutSize != NULL) {
|
||||
*DataOutSize = DataInSize;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
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
|
||||
AeadAesGcmDecrypt (
|
||||
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
|
||||
)
|
||||
{
|
||||
mbedtls_gcm_context Ctx;
|
||||
INT32 Ret;
|
||||
|
||||
if (DataInSize > INT_MAX) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ADataSize > INT_MAX) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (IvSize != 12) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch (KeySize) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((TagSize != 12) && (TagSize != 13) && (TagSize != 14) && (TagSize != 15) && (TagSize != 16)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (DataOutSize != NULL) {
|
||||
if ((*DataOutSize > INT_MAX) || (*DataOutSize < DataInSize)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_gcm_init (&Ctx);
|
||||
|
||||
Ret = mbedtls_gcm_setkey (&Ctx, MBEDTLS_CIPHER_ID_AES, Key, (UINT32)(KeySize * 8));
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_gcm_auth_decrypt (
|
||||
&Ctx,
|
||||
(UINT32)DataInSize,
|
||||
Iv,
|
||||
(UINT32)IvSize,
|
||||
AData,
|
||||
(UINT32)ADataSize,
|
||||
Tag,
|
||||
(UINT32)TagSize,
|
||||
DataIn,
|
||||
DataOut
|
||||
);
|
||||
mbedtls_gcm_free (&Ctx);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (DataOutSize != NULL) {
|
||||
*DataOutSize = DataInSize;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -8,7 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/md5.h>
|
||||
#include <mbedtls/compat-2.x.h>
|
||||
|
||||
#ifdef ENABLE_MD5_DEPRECATED_INTERFACES
|
||||
|
||||
@ -56,7 +55,7 @@ Md5Init (
|
||||
|
||||
mbedtls_md5_init (Md5Context);
|
||||
|
||||
Ret = mbedtls_md5_starts_ret (Md5Context);
|
||||
Ret = mbedtls_md5_starts (Md5Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -129,7 +128,7 @@ Md5Update (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_md5_update_ret (Md5Context, Data, DataSize);
|
||||
Ret = mbedtls_md5_update (Md5Context, Data, DataSize);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -170,7 +169,7 @@ Md5Final (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_md5_finish_ret (Md5Context, HashValue);
|
||||
Ret = mbedtls_md5_finish (Md5Context, HashValue);
|
||||
mbedtls_md5_free (Md5Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
@ -215,7 +214,7 @@ Md5HashAll (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_md5_ret (Data, DataSize, HashValue);
|
||||
Ret = mbedtls_md5 (Data, DataSize, HashValue);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/sha1.h>
|
||||
#include <mbedtls/compat-2.x.h>
|
||||
|
||||
#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
|
||||
|
||||
@ -56,7 +55,7 @@ Sha1Init (
|
||||
|
||||
mbedtls_sha1_init (Sha1Context);
|
||||
|
||||
Ret = mbedtls_sha1_starts_ret (Sha1Context);
|
||||
Ret = mbedtls_sha1_starts (Sha1Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -129,7 +128,7 @@ Sha1Update (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha1_update_ret (Sha1Context, Data, DataSize);
|
||||
Ret = mbedtls_sha1_update (Sha1Context, Data, DataSize);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -170,7 +169,7 @@ Sha1Final (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha1_finish_ret (Sha1Context, HashValue);
|
||||
Ret = mbedtls_sha1_finish (Sha1Context, HashValue);
|
||||
mbedtls_sha1_free (Sha1Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
@ -215,7 +214,7 @@ Sha1HashAll (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha1_ret (Data, DataSize, HashValue);
|
||||
Ret = mbedtls_sha1 (Data, DataSize, HashValue);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/sha256.h>
|
||||
#include <mbedtls/compat-2.x.h>
|
||||
|
||||
/**
|
||||
Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
|
||||
@ -51,7 +50,7 @@ Sha256Init (
|
||||
|
||||
mbedtls_sha256_init (Sha256Context);
|
||||
|
||||
Ret = mbedtls_sha256_starts_ret (Sha256Context, FALSE);
|
||||
Ret = mbedtls_sha256_starts (Sha256Context, FALSE);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -124,7 +123,7 @@ Sha256Update (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha256_update_ret (Sha256Context, Data, DataSize);
|
||||
Ret = mbedtls_sha256_update (Sha256Context, Data, DataSize);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -165,7 +164,7 @@ Sha256Final (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha256_finish_ret (Sha256Context, HashValue);
|
||||
Ret = mbedtls_sha256_finish (Sha256Context, HashValue);
|
||||
mbedtls_sha256_free (Sha256Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
@ -210,7 +209,7 @@ Sha256HashAll (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha256_ret (Data, DataSize, HashValue, FALSE);
|
||||
Ret = mbedtls_sha256 (Data, DataSize, HashValue, FALSE);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/sha512.h>
|
||||
#include <mbedtls/compat-2.x.h>
|
||||
|
||||
/**
|
||||
Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
|
||||
@ -51,7 +50,7 @@ Sha384Init (
|
||||
|
||||
mbedtls_sha512_init (Sha384Context);
|
||||
|
||||
Ret = mbedtls_sha512_starts_ret (Sha384Context, TRUE);
|
||||
Ret = mbedtls_sha512_starts (Sha384Context, TRUE);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -126,7 +125,7 @@ Sha384Update (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha512_update_ret (Sha384Context, Data, DataSize);
|
||||
Ret = mbedtls_sha512_update (Sha384Context, Data, DataSize);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -167,7 +166,7 @@ Sha384Final (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha512_finish_ret (Sha384Context, HashValue);
|
||||
Ret = mbedtls_sha512_finish (Sha384Context, HashValue);
|
||||
mbedtls_sha512_free (Sha384Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
@ -212,7 +211,7 @@ Sha384HashAll (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha512_ret (Data, DataSize, HashValue, TRUE);
|
||||
Ret = mbedtls_sha512 (Data, DataSize, HashValue, TRUE);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -261,7 +260,7 @@ Sha512Init (
|
||||
|
||||
mbedtls_sha512_init (Sha512Context);
|
||||
|
||||
Ret = mbedtls_sha512_starts_ret (Sha512Context, FALSE);
|
||||
Ret = mbedtls_sha512_starts (Sha512Context, FALSE);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -336,7 +335,7 @@ Sha512Update (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha512_update_ret (Sha512Context, Data, DataSize);
|
||||
Ret = mbedtls_sha512_update (Sha512Context, Data, DataSize);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -377,7 +376,7 @@ Sha512Final (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha512_finish_ret (Sha512Context, HashValue);
|
||||
Ret = mbedtls_sha512_finish (Sha512Context, HashValue);
|
||||
mbedtls_sha512_free (Sha512Context);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
@ -422,7 +421,7 @@ Sha512HashAll (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_sha512_ret (Data, DataSize, HashValue, FALSE);
|
||||
Ret = mbedtls_sha512 (Data, DataSize, HashValue, FALSE);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
235
CryptoPkg/Library/BaseCryptLibMbedTls/Hash/CryptSm3.c
Normal file
235
CryptoPkg/Library/BaseCryptLibMbedTls/Hash/CryptSm3.c
Normal file
@ -0,0 +1,235 @@
|
||||
/** @file
|
||||
SM3 Digest Wrapper Implementations over openssl.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include "internal/sm3.h"
|
||||
|
||||
/**
|
||||
Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
|
||||
|
||||
@return The size, in bytes, of the context buffer required for SM3 hash operations.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
EFIAPI
|
||||
Sm3GetContextSize (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
//
|
||||
// Retrieves Openssl SM3 Context Size
|
||||
//
|
||||
return (UINTN)(sizeof (SM3_CTX));
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
|
||||
subsequent use.
|
||||
|
||||
If Sm3Context is NULL, then return FALSE.
|
||||
|
||||
@param[out] Sm3Context Pointer to SM3 context being initialized.
|
||||
|
||||
@retval TRUE SM3 context initialization succeeded.
|
||||
@retval FALSE SM3 context initialization failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Sm3Init (
|
||||
OUT VOID *Sm3Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if (Sm3Context == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Openssl SM3 Context Initialization
|
||||
//
|
||||
ossl_sm3_init ((SM3_CTX *)Sm3Context);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Makes a copy of an existing SM3 context.
|
||||
|
||||
If Sm3Context is NULL, then return FALSE.
|
||||
If NewSm3Context is NULL, then return FALSE.
|
||||
If this interface is not supported, then return FALSE.
|
||||
|
||||
@param[in] Sm3Context Pointer to SM3 context being copied.
|
||||
@param[out] NewSm3Context Pointer to new SM3 context.
|
||||
|
||||
@retval TRUE SM3 context copy succeeded.
|
||||
@retval FALSE SM3 context copy failed.
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Sm3Duplicate (
|
||||
IN CONST VOID *Sm3Context,
|
||||
OUT VOID *NewSm3Context
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((Sm3Context == NULL) || (NewSm3Context == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMem (NewSm3Context, Sm3Context, sizeof (SM3_CTX));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Digests the input data and updates SM3 context.
|
||||
|
||||
This function performs SM3 digest on a data buffer of the specified size.
|
||||
It can be called multiple times to compute the digest of long or discontinuous data streams.
|
||||
SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
|
||||
by Sm3Final(). Behavior with invalid context is undefined.
|
||||
|
||||
If Sm3Context is NULL, then return FALSE.
|
||||
|
||||
@param[in, out] Sm3Context Pointer to the SM3 context.
|
||||
@param[in] Data Pointer to the buffer containing the data to be hashed.
|
||||
@param[in] DataSize Size of Data buffer in bytes.
|
||||
|
||||
@retval TRUE SM3 data digest succeeded.
|
||||
@retval FALSE SM3 data digest failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Sm3Update (
|
||||
IN OUT VOID *Sm3Context,
|
||||
IN CONST VOID *Data,
|
||||
IN UINTN DataSize
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if (Sm3Context == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check invalid parameters, in case that only DataLength was checked in Openssl
|
||||
//
|
||||
if ((Data == NULL) && (DataSize != 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Openssl SM3 Hash Update
|
||||
//
|
||||
ossl_sm3_update ((SM3_CTX *)Sm3Context, Data, DataSize);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Completes computation of the SM3 digest value.
|
||||
|
||||
This function completes SM3 hash computation and retrieves the digest value into
|
||||
the specified memory. After this function has been called, the SM3 context cannot
|
||||
be used again.
|
||||
SM3 context should be already correctly initialized by Sm3Init(), and should not be
|
||||
finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
|
||||
|
||||
If Sm3Context is NULL, then return FALSE.
|
||||
If HashValue is NULL, then return FALSE.
|
||||
|
||||
@param[in, out] Sm3Context Pointer to the SM3 context.
|
||||
@param[out] HashValue Pointer to a buffer that receives the SM3 digest
|
||||
value (32 bytes).
|
||||
|
||||
@retval TRUE SM3 digest computation succeeded.
|
||||
@retval FALSE SM3 digest computation failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Sm3Final (
|
||||
IN OUT VOID *Sm3Context,
|
||||
OUT UINT8 *HashValue
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((Sm3Context == NULL) || (HashValue == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Openssl SM3 Hash Finalization
|
||||
//
|
||||
ossl_sm3_final (HashValue, (SM3_CTX *)Sm3Context);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Computes the SM3 message digest of a input data buffer.
|
||||
|
||||
This function performs the SM3 message digest of a given data buffer, and places
|
||||
the digest value into the specified memory.
|
||||
|
||||
If this interface is not supported, then return FALSE.
|
||||
|
||||
@param[in] Data Pointer to the buffer containing the data to be hashed.
|
||||
@param[in] DataSize Size of Data buffer in bytes.
|
||||
@param[out] HashValue Pointer to a buffer that receives the SM3 digest
|
||||
value (32 bytes).
|
||||
|
||||
@retval TRUE SM3 digest computation succeeded.
|
||||
@retval FALSE SM3 digest computation failed.
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Sm3HashAll (
|
||||
IN CONST VOID *Data,
|
||||
IN UINTN DataSize,
|
||||
OUT UINT8 *HashValue
|
||||
)
|
||||
{
|
||||
SM3_CTX Ctx;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if (HashValue == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((Data == NULL) && (DataSize != 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// SM3 Hash Computation.
|
||||
//
|
||||
ossl_sm3_init (&Ctx);
|
||||
|
||||
ossl_sm3_update (&Ctx, Data, DataSize);
|
||||
|
||||
ossl_sm3_final (HashValue, &Ctx);
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -22,4 +22,53 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
//
|
||||
#include <mbedtls/mbedtls_config.h>
|
||||
|
||||
/**
|
||||
The MbedTLS function f_rng, which MbedtlsRand implements.
|
||||
|
||||
@param[in] RngState Not used, just for compatibility with mbedlts.
|
||||
@param[out] Output Pointer to buffer to receive random value.
|
||||
@param[in] Len Size of random bytes to generate.
|
||||
|
||||
@retval 0 Pseudorandom byte stream generated successfully.
|
||||
@retval Non-0 Pseudorandom number generator fails to generate due to lack of entropy.
|
||||
**/
|
||||
INT32
|
||||
MbedtlsRand (
|
||||
VOID *RngState,
|
||||
UINT8 *Output,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
/**
|
||||
Check input P7Data is a wrapped ContentInfo structure or not. If not construct
|
||||
a new structure to wrap P7Data.
|
||||
|
||||
Caution: This function may receive untrusted input.
|
||||
UEFI Authenticated Variable is external input, so this function will do basic
|
||||
check for PKCS#7 data structure.
|
||||
|
||||
@param[in] P7Data Pointer to the PKCS#7 message to verify.
|
||||
@param[in] P7Length Length of the PKCS#7 message in bytes.
|
||||
@param[out] WrapFlag If TRUE P7Data is a ContentInfo structure, otherwise
|
||||
return FALSE.
|
||||
@param[out] WrapData If return status of this function is TRUE:
|
||||
1) when WrapFlag is TRUE, pointer to P7Data.
|
||||
2) when WrapFlag is FALSE, pointer to a new ContentInfo
|
||||
structure. It's caller's responsibility to free this
|
||||
buffer.
|
||||
@param[out] WrapDataSize Length of ContentInfo structure in bytes.
|
||||
|
||||
@retval TRUE The operation is finished successfully.
|
||||
@retval FALSE The operation is failed due to lack of resources.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
WrapPkcs7Data (
|
||||
IN CONST UINT8 *P7Data,
|
||||
IN UINTN P7Length,
|
||||
OUT BOOLEAN *WrapFlag,
|
||||
OUT UINT8 **WrapData,
|
||||
OUT UINTN *WrapDataSize
|
||||
);
|
||||
|
||||
#endif
|
||||
|
@ -38,31 +38,35 @@
|
||||
Hash/CryptMd5.c
|
||||
Hash/CryptSha1.c
|
||||
Hash/CryptSha256.c
|
||||
Hash/CryptSm3Null.c
|
||||
Hash/CryptSha512.c
|
||||
Hash/CryptParallelHashNull.c
|
||||
Hash/CryptSm3.c
|
||||
Hmac/CryptHmac.c
|
||||
Kdf/CryptHkdf.c
|
||||
Cipher/CryptAes.c
|
||||
Cipher/CryptAeadAesGcmNull.c
|
||||
Pk/CryptRsaBasic.c
|
||||
Pk/CryptRsaExtNull.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Bn/CryptBnNull.c
|
||||
Pem/CryptPemNull.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pk/CryptPkcs1OaepNull.c
|
||||
Pk/CryptPkcs5Pbkdf2Null.c
|
||||
Pk/CryptPkcs7SignNull.c
|
||||
Pk/CryptPkcs7VerifyNull.c
|
||||
Pk/CryptPkcs7VerifyEkuNull.c
|
||||
Pk/CryptPkcs7VerifyCommon.c
|
||||
Pk/CryptPkcs7VerifyBase.c
|
||||
Pk/CryptPkcs7VerifyEku.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptX509Null.c
|
||||
Pk/CryptAuthenticodeNull.c
|
||||
Pk/CryptTsNull.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pem/CryptPemNull.c
|
||||
Rand/CryptRandNull.c
|
||||
Bn/CryptBnNull.c
|
||||
|
||||
SysCall/CrtWrapper.c
|
||||
SysCall/DummyOpensslSupport.c
|
||||
SysCall/BaseMemAllocation.c
|
||||
SysCall/ConstantTimeClock.c
|
||||
|
||||
[Packages]
|
||||
@ -75,6 +79,7 @@
|
||||
MemoryAllocationLib
|
||||
DebugLib
|
||||
MbedTlsLib
|
||||
OpensslLib
|
||||
IntrinsicLib
|
||||
PrintLib
|
||||
PeiServicesTablePointerLib
|
||||
|
138
CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c
Normal file
138
CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c
Normal file
@ -0,0 +1,138 @@
|
||||
/** @file
|
||||
PEM (Privacy Enhanced Mail) Format Handler Wrapper Implementation over MbedTLS.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/pem.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include <mbedtls/rsa.h>
|
||||
#include <mbedtls/ecp.h>
|
||||
#include <mbedtls/ecdh.h>
|
||||
#include <mbedtls/ecdsa.h>
|
||||
|
||||
/**
|
||||
Retrieve the RSA 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] RsaContext Pointer to new-generated RSA context which contain the retrieved
|
||||
RSA private key component. Use RsaFree() function to free the
|
||||
resource.
|
||||
|
||||
If PemData is NULL, then return FALSE.
|
||||
If RsaContext is NULL, then return FALSE.
|
||||
|
||||
@retval TRUE RSA Private Key was retrieved successfully.
|
||||
@retval FALSE Invalid PEM key data or incorrect password.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaGetPrivateKeyFromPem (
|
||||
IN CONST UINT8 *PemData,
|
||||
IN UINTN PemSize,
|
||||
IN CONST CHAR8 *Password,
|
||||
OUT VOID **RsaContext
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
mbedtls_pk_context Pk;
|
||||
mbedtls_rsa_context *Rsa;
|
||||
UINT8 *NewPemData;
|
||||
UINTN PasswordLen;
|
||||
|
||||
if ((PemData == NULL) || (RsaContext == NULL) || (PemSize > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
NewPemData = NULL;
|
||||
if (PemData[PemSize - 1] != 0) {
|
||||
NewPemData = AllocateZeroPool (PemSize + 1);
|
||||
if (NewPemData == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMem (NewPemData, PemData, PemSize + 1);
|
||||
NewPemData[PemSize] = 0;
|
||||
PemData = NewPemData;
|
||||
PemSize += 1;
|
||||
}
|
||||
|
||||
mbedtls_pk_init (&Pk);
|
||||
|
||||
if (Password != NULL) {
|
||||
PasswordLen = AsciiStrLen (Password);
|
||||
} else {
|
||||
PasswordLen = 0;
|
||||
}
|
||||
|
||||
Ret = mbedtls_pk_parse_key (&Pk, PemData, PemSize, (CONST UINT8 *)Password, PasswordLen, NULL, NULL);
|
||||
|
||||
if (NewPemData != NULL) {
|
||||
FreePool (NewPemData);
|
||||
NewPemData = NULL;
|
||||
}
|
||||
|
||||
if (Ret != 0) {
|
||||
mbedtls_pk_free (&Pk);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_pk_get_type (&Pk) != MBEDTLS_PK_RSA) {
|
||||
mbedtls_pk_free (&Pk);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Rsa = RsaNew ();
|
||||
if (Rsa == NULL) {
|
||||
mbedtls_pk_free (&Pk);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_copy (Rsa, mbedtls_pk_rsa (Pk));
|
||||
if (Ret != 0) {
|
||||
RsaFree (Rsa);
|
||||
mbedtls_pk_free (&Pk);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mbedtls_pk_free (&Pk);
|
||||
|
||||
*RsaContext = Rsa;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieve the EC 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] EcContext Pointer to new-generated EC DSA context which contain the retrieved
|
||||
EC private key component. Use EcFree() function to free the
|
||||
resource.
|
||||
|
||||
If PemData is NULL, then return FALSE.
|
||||
If EcContext is NULL, then return FALSE.
|
||||
|
||||
@retval TRUE EC Private Key was retrieved successfully.
|
||||
@retval FALSE Invalid PEM key data or incorrect password.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
EcGetPrivateKeyFromPem (
|
||||
IN CONST UINT8 *PemData,
|
||||
IN UINTN PemSize,
|
||||
IN CONST CHAR8 *Password,
|
||||
OUT VOID **EcContext
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
214
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptAuthenticode.c
Normal file
214
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptAuthenticode.c
Normal file
@ -0,0 +1,214 @@
|
||||
/** @file
|
||||
Authenticode Portable Executable Signature Verification which does not provide
|
||||
real capabilities.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/pkcs7.h>
|
||||
|
||||
//
|
||||
// OID ASN.1 Value for SPC_INDIRECT_DATA_OBJID
|
||||
//
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 mSpcIndirectOidValue[] = {
|
||||
0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04
|
||||
};
|
||||
|
||||
/**
|
||||
Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
|
||||
Authenticode Portable Executable Signature Format".
|
||||
|
||||
Return FALSE to indicate this interface is not supported.
|
||||
|
||||
@param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
|
||||
PE/COFF image to be verified.
|
||||
@param[in] DataSize Size of the Authenticode Signature in bytes.
|
||||
@param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
|
||||
is used for certificate chain verification.
|
||||
@param[in] CertSize Size of the trusted certificate in bytes.
|
||||
@param[in] ImageHash Pointer to the original image file hash value. The procedure
|
||||
for calculating the image hash value is described in Authenticode
|
||||
specification.
|
||||
@param[in] HashSize Size of Image hash value in bytes.
|
||||
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
AuthenticodeVerify (
|
||||
IN CONST UINT8 *AuthData,
|
||||
IN UINTN DataSize,
|
||||
IN CONST UINT8 *TrustedCert,
|
||||
IN UINTN CertSize,
|
||||
IN CONST UINT8 *ImageHash,
|
||||
IN UINTN HashSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
CONST UINT8 *OrigAuthData;
|
||||
UINT8 *SpcIndirectDataContent;
|
||||
UINT8 Asn1Byte;
|
||||
UINTN ContentSize;
|
||||
CONST UINT8 *SpcIndirectDataOid;
|
||||
UINT8 *Ptr;
|
||||
UINT8 *End;
|
||||
INT32 Len;
|
||||
UINTN ObjLen;
|
||||
|
||||
OrigAuthData = AuthData;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((AuthData == NULL) || (TrustedCert == NULL) || (ImageHash == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((DataSize > INT_MAX) || (CertSize > INT_MAX) || (HashSize > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (DataSize <= HashSize) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr = (UINT8 *)(UINTN)AuthData;
|
||||
Len = (UINT32)DataSize;
|
||||
End = Ptr + Len;
|
||||
|
||||
// ContentInfo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ContentType
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// content
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
End = Ptr + ObjLen;
|
||||
// signedData
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// version
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// digestAlgo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// encapContentInfo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
End = Ptr + ObjLen;
|
||||
// eContentType
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = FALSE;
|
||||
|
||||
SpcIndirectDataOid = Ptr;
|
||||
if ((ObjLen != sizeof (mSpcIndirectOidValue)) ||
|
||||
(CompareMem (
|
||||
SpcIndirectDataOid,
|
||||
mSpcIndirectOidValue,
|
||||
sizeof (mSpcIndirectOidValue)
|
||||
) != 0))
|
||||
{
|
||||
//
|
||||
// Un-matched SPC_INDIRECT_DATA_OBJID.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// eContent
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SpcIndirectDataContent = Ptr;
|
||||
|
||||
//
|
||||
// Retrieve the SEQUENCE data size from ASN.1-encoded SpcIndirectDataContent.
|
||||
//
|
||||
Asn1Byte = *(SpcIndirectDataContent + 1);
|
||||
|
||||
if ((Asn1Byte & 0x80) == 0) {
|
||||
//
|
||||
// Short Form of Length Encoding (Length < 128)
|
||||
//
|
||||
ContentSize = (UINTN)(Asn1Byte & 0x7F);
|
||||
//
|
||||
// Skip the SEQUENCE Tag;
|
||||
//
|
||||
SpcIndirectDataContent += 2;
|
||||
} else if ((Asn1Byte & 0x81) == 0x81) {
|
||||
//
|
||||
// Long Form of Length Encoding (128 <= Length < 255, Single Octet)
|
||||
//
|
||||
ContentSize = (UINTN)(*(UINT8 *)(SpcIndirectDataContent + 2));
|
||||
//
|
||||
// Skip the SEQUENCE Tag;
|
||||
//
|
||||
SpcIndirectDataContent += 3;
|
||||
} else if ((Asn1Byte & 0x82) == 0x82) {
|
||||
//
|
||||
// Long Form of Length Encoding (Length > 255, Two Octet)
|
||||
//
|
||||
ContentSize = (UINTN)(*(UINT8 *)(SpcIndirectDataContent + 2));
|
||||
ContentSize = (ContentSize << 8) + (UINTN)(*(UINT8 *)(SpcIndirectDataContent + 3));
|
||||
//
|
||||
// Skip the SEQUENCE Tag;
|
||||
//
|
||||
SpcIndirectDataContent += 4;
|
||||
} else {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Compare the original file hash value to the digest retrieve from SpcIndirectDataContent
|
||||
// defined in Authenticode
|
||||
// NOTE: Need to double-check HashLength here!
|
||||
//
|
||||
if (ContentSize < HashSize) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (CompareMem (SpcIndirectDataContent + ContentSize - HashSize, ImageHash, HashSize) != 0) {
|
||||
//
|
||||
// Un-matched PE/COFF Hash Value
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Verifies the PKCS#7 Signed Data in PE/COFF Authenticode Signature
|
||||
//
|
||||
Status = (BOOLEAN)Pkcs7Verify (OrigAuthData, DataSize, TrustedCert, CertSize, SpcIndirectDataContent, ContentSize);
|
||||
|
||||
_Exit:
|
||||
|
||||
return Status;
|
||||
}
|
278
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs1Oaep.c
Normal file
278
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs1Oaep.c
Normal file
@ -0,0 +1,278 @@
|
||||
/** @file
|
||||
This file contains UEFI wrapper functions for RSA PKCS1v2 OAEP encryption routines.
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/rsa.h>
|
||||
#include <mbedtls/x509_crt.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to parse X509 certificate.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] PublicKey A pointer to the DER-encoded X509 certificate that
|
||||
will be used to encrypt the data.
|
||||
@param[in] PublicKeySize Size of the X509 cert buffer.
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Encrypt (
|
||||
IN CONST UINT8 *PublicKey,
|
||||
IN UINTN PublicKeySize,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
UINT32 Ret;
|
||||
UINT8 *OutData;
|
||||
mbedtls_x509_crt CertContext;
|
||||
mbedtls_rsa_context RsaContext;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((PublicKey == NULL) || (InData == NULL) ||
|
||||
(EncryptedData == NULL) || (EncryptedDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check public key size.
|
||||
//
|
||||
if (PublicKeySize > UINT_MAX) {
|
||||
//
|
||||
// Public key size is too large for implementation.
|
||||
//
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*EncryptedData = NULL;
|
||||
*EncryptedDataSize = 0;
|
||||
Result = FALSE;
|
||||
OutData = NULL;
|
||||
|
||||
mbedtls_x509_crt_init (&CertContext);
|
||||
|
||||
if (mbedtls_x509_crt_parse_der (&CertContext, PublicKey, (UINT32)PublicKeySize) != 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
if (mbedtls_pk_get_type (&CertContext.pk) != MBEDTLS_PK_RSA) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
mbedtls_rsa_init (&RsaContext);
|
||||
if (mbedtls_rsa_set_padding (&RsaContext, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_NONE) != 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_copy (&RsaContext, mbedtls_pk_rsa (CertContext.pk));
|
||||
if (Ret != 0) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
*EncryptedDataSize = RsaContext.len;
|
||||
|
||||
//
|
||||
// Allocate a buffer for the output data.
|
||||
//
|
||||
OutData = AllocateZeroPool (*EncryptedDataSize);
|
||||
if (OutData == NULL) {
|
||||
//
|
||||
// Fail to allocate the output buffer.
|
||||
//
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_pkcs1_encrypt (
|
||||
&RsaContext,
|
||||
MbedtlsRand,
|
||||
NULL,
|
||||
InDataSize,
|
||||
InData,
|
||||
OutData
|
||||
);
|
||||
if (Ret != 0) {
|
||||
FreePool (OutData);
|
||||
OutData = NULL;
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
*EncryptedData = OutData;
|
||||
Result = TRUE;
|
||||
|
||||
_Exit:
|
||||
//
|
||||
// Release Resources
|
||||
//
|
||||
if (&CertContext != NULL) {
|
||||
mbedtls_x509_crt_free (&CertContext);
|
||||
}
|
||||
|
||||
if (&RsaContext != NULL) {
|
||||
mbedtls_rsa_free (&RsaContext);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
@ -38,10 +39,8 @@ Pkcs1v2Encrypt (
|
||||
IN UINTN PublicKeySize,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed,
|
||||
OPTIONAL
|
||||
IN UINTN PrngSeedSize,
|
||||
OPTIONAL
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
@ -49,3 +48,131 @@ Pkcs1v2Encrypt (
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
100
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs5Pbkdf2.c
Normal file
100
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs5Pbkdf2.c
Normal file
@ -0,0 +1,100 @@
|
||||
/** @file
|
||||
PBKDF2 Key Derivation Function Wrapper Implementation over MbedTLS.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/pkcs5.h>
|
||||
|
||||
/**
|
||||
Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
|
||||
password based encryption key derivation function PBKDF2, as specified in RFC 2898.
|
||||
|
||||
If Password or Salt or OutKey is NULL, then return FALSE.
|
||||
If the hash algorithm could not be determined, then return FALSE.
|
||||
|
||||
@param[in] PasswordLength Length of input password in bytes.
|
||||
@param[in] Password Pointer to the array for the password.
|
||||
@param[in] SaltLength Size of the Salt in bytes.
|
||||
@param[in] Salt Pointer to the Salt.
|
||||
@param[in] IterationCount Number of iterations to perform. Its value should be
|
||||
greater than or equal to 1.
|
||||
@param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
|
||||
NOTE: DigestSize will be used to determine the hash algorithm.
|
||||
Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
|
||||
@param[in] KeyLength Size of the derived key buffer in bytes.
|
||||
@param[out] OutKey Pointer to the output derived key buffer.
|
||||
|
||||
@retval TRUE A key was derived successfully.
|
||||
@retval FALSE One of the pointers was NULL or one of the sizes was too large.
|
||||
@retval FALSE The hash algorithm could not be determined from the digest size.
|
||||
@retval FALSE The key derivation operation failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs5HashPassword (
|
||||
IN UINTN PasswordLength,
|
||||
IN CONST CHAR8 *Password,
|
||||
IN UINTN SaltLength,
|
||||
IN CONST UINT8 *Salt,
|
||||
IN UINTN IterationCount,
|
||||
IN UINTN DigestSize,
|
||||
IN UINTN KeyLength,
|
||||
OUT UINT8 *OutKey
|
||||
)
|
||||
{
|
||||
mbedtls_md_type_t HashAlg;
|
||||
|
||||
//
|
||||
// Parameter Checking.
|
||||
//
|
||||
if ((Password == NULL) || (Salt == NULL) || (OutKey == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((PasswordLength == 0) || (PasswordLength > INT_MAX) ||
|
||||
(SaltLength == 0) || (SaltLength > INT_MAX) ||
|
||||
(KeyLength == 0) || (KeyLength > INT_MAX) ||
|
||||
(IterationCount < 1) || (IterationCount > INT_MAX))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure the digest algorithm is supported.
|
||||
//
|
||||
switch (DigestSize) {
|
||||
case SHA1_DIGEST_SIZE:
|
||||
HashAlg = MBEDTLS_MD_SHA1;
|
||||
break;
|
||||
case SHA256_DIGEST_SIZE:
|
||||
HashAlg = MBEDTLS_MD_SHA256;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Perform password-based key derivation routines.
|
||||
//
|
||||
if (mbedtls_pkcs5_pbkdf2_hmac_ext (
|
||||
HashAlg,
|
||||
(CONST UINT8 *)Password,
|
||||
(int)PasswordLength,
|
||||
(CONST UINT8 *)Salt,
|
||||
(int)SaltLength,
|
||||
(int)IterationCount,
|
||||
(int)KeyLength,
|
||||
(UINT8 *)OutKey
|
||||
) != 0)
|
||||
{
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
|
||||
RFC 2315 - PKCS #7: Cryptographic Message Syntax Version 1.5
|
||||
|
||||
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2023-2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
@ -31,10 +31,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#define MBEDTLS_OID_PKCS7_DIGESTED_DATA MBEDTLS_OID_PKCS7 "\x05"
|
||||
#define MBEDTLS_OID_PKCS7_ENCRYPTED_DATA MBEDTLS_OID_PKCS7 "\x06"
|
||||
|
||||
typedef mbedtls_asn1_buf MBEDTLSPKCS7BUF;
|
||||
typedef mbedtls_asn1_named_data MBEDTLSPKCS7NAME;
|
||||
typedef mbedtls_asn1_sequence MBEDTLSPKCS7SEQUENCE;
|
||||
|
||||
///
|
||||
/// PKCS7 SignerInfo type
|
||||
/// https://tools.ietf.org/html/rfc2315#section-9.2
|
||||
@ -48,8 +44,8 @@ typedef struct MbedtlsPkcs7SignerInfo {
|
||||
mbedtls_x509_buf SigAlgIdentifier;
|
||||
mbedtls_x509_buf AuthAttr;
|
||||
mbedtls_x509_buf Sig;
|
||||
struct MBEDTLSPKCS7SIGNERINFO *Next;
|
||||
} MBEDTLSPKCS7SIGNERINFO;
|
||||
struct MbedtlsPkcs7SignerInfo *Next;
|
||||
} MbedtlsPkcs7SignerInfo;
|
||||
|
||||
///
|
||||
/// PKCS7 signed data attached data format
|
||||
@ -57,7 +53,7 @@ typedef struct MbedtlsPkcs7SignerInfo {
|
||||
typedef struct MbedtlsPkcs7Data {
|
||||
mbedtls_asn1_buf Oid;
|
||||
mbedtls_asn1_buf Data;
|
||||
} MBEDTLSPKCS7DATA;
|
||||
} MbedtlsPkcs7Data;
|
||||
|
||||
///
|
||||
/// Signed Data
|
||||
@ -66,18 +62,27 @@ typedef struct MbedtlsPkcs7Data {
|
||||
typedef struct MbedtlsPkcs7SignedData {
|
||||
INT32 Version;
|
||||
mbedtls_asn1_buf DigestAlgorithms;
|
||||
struct MBEDTLSPKCS7DATA ContentInfo;
|
||||
struct MbedtlsPkcs7Data ContentInfo;
|
||||
mbedtls_x509_crt Certificates;
|
||||
mbedtls_x509_crl Crls;
|
||||
struct MbedtlsPkcs7SignerInfo SignerInfos;
|
||||
} MBEDTLSPKCS7SIGNEDDATA;
|
||||
} MbedtlsPkcs7SignedData;
|
||||
|
||||
///
|
||||
/// PKCS7 struct, only support SignedData
|
||||
///
|
||||
typedef struct MbedtlsPkcs7 {
|
||||
mbedtls_asn1_buf ContentTypeOid;
|
||||
struct MBEDTLSPKCS7SIGNEDDATA SignedData;
|
||||
} MBEDTLSPKCS7;
|
||||
struct MbedtlsPkcs7SignedData SignedData;
|
||||
} MbedtlsPkcs7;
|
||||
|
||||
#define EDKII_ASN1_CHK_ADD(g, f) \
|
||||
do \
|
||||
{ \
|
||||
if( ( Ret = (f) ) < 0 ) \
|
||||
return( Ret ); \
|
||||
else \
|
||||
(g) += Ret; \
|
||||
} while( 0 )
|
||||
|
||||
#endif
|
||||
|
635
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7Sign.c
Normal file
635
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7Sign.c
Normal file
@ -0,0 +1,635 @@
|
||||
/** @file
|
||||
PKCS#7 SignedData Sign Wrapper and PKCS#7 SignedData Verification Wrapper
|
||||
Implementation over mbedtls.
|
||||
|
||||
RFC 8422 - Elliptic Curve Cryptography (ECC) Cipher Suites
|
||||
FIPS 186-4 - Digital Signature Standard (DSS)
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "CryptPkcs7Internal.h"
|
||||
#include <mbedtls/ecdh.h>
|
||||
|
||||
///
|
||||
/// Enough to store any signature generated by PKCS7
|
||||
///
|
||||
#define MAX_SIGNATURE_SIZE 1024
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MbedtlsOidDigestAlgSha256[] = MBEDTLS_OID_DIGEST_ALG_SHA256;
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MbedtlsOidPkcs1Rsa[] = MBEDTLS_OID_PKCS1_RSA;
|
||||
|
||||
/**
|
||||
Write DigestAlgorithmIdentifier.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] DigestType Digest Type
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteDigestAlgorithm (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
mbedtls_md_type_t DigestType
|
||||
)
|
||||
{
|
||||
UINT8 *OidPtr;
|
||||
UINTN OidLen;
|
||||
INT32 Ret;
|
||||
|
||||
Ret = mbedtls_oid_get_oid_by_md (DigestType, (CONST CHAR8 **)&OidPtr, &OidLen);
|
||||
if (Ret == 0) {
|
||||
return mbedtls_asn1_write_oid (Ptr, (CONST UINT8 *)Start, (CONST CHAR8 *)OidPtr, OidLen);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
DigestAlgorithmIdentifiers ::=
|
||||
SET OF DigestAlgorithmIdentifier.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] DigestTypes Digest Type array.
|
||||
@param[in] Count The index for Digest Type.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteDigestAlgorithmSet (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
mbedtls_md_type_t *DigestTypes,
|
||||
INTN Count
|
||||
)
|
||||
{
|
||||
INTN Idx;
|
||||
INT32 Len;
|
||||
INT32 Ret;
|
||||
|
||||
Len = 0;
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_null (Ptr, Start));
|
||||
|
||||
for (Idx = 0; Idx < Count; Idx++) {
|
||||
EDKII_ASN1_CHK_ADD (
|
||||
Len,
|
||||
MbedTlsPkcs7WriteDigestAlgorithm (Ptr, Start, DigestTypes[Idx])
|
||||
);
|
||||
}
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, (UINTN)Len));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (
|
||||
Len,
|
||||
mbedtls_asn1_write_tag (
|
||||
Ptr,
|
||||
Start,
|
||||
(MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)
|
||||
)
|
||||
);
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, (UINTN)Len));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (
|
||||
Len,
|
||||
mbedtls_asn1_write_tag (
|
||||
Ptr,
|
||||
Start,
|
||||
(MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)
|
||||
)
|
||||
);
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
ContentInfo ::= SEQUENCE {
|
||||
contentType ContentType,
|
||||
content
|
||||
[0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] Content ContentInfo.
|
||||
@param[in] ContentLen Size of ContentInfo.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteContentInfo (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
UINT8 *Content,
|
||||
INTN ContentLen
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
INT32 Len;
|
||||
|
||||
Len = 0;
|
||||
if (Content != NULL) {
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_octet_string (Ptr, Start, Content, ContentLen));
|
||||
}
|
||||
|
||||
EDKII_ASN1_CHK_ADD (
|
||||
Len,
|
||||
mbedtls_asn1_write_oid (
|
||||
Ptr,
|
||||
Start,
|
||||
MBEDTLS_OID_PKCS7_DATA,
|
||||
sizeof (MBEDTLS_OID_PKCS7_DATA) - 1
|
||||
)
|
||||
);
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
certificates :: SET OF ExtendedCertificateOrCertificate,
|
||||
ExtendedCertificateOrCertificate ::= CHOICE {
|
||||
certificate Certificate -- x509,
|
||||
extendedCertificate[0] IMPLICIT ExtendedCertificate }.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] Cert Certificate.
|
||||
@param[in] OtherCerts Ohter Certificate.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteCertificates (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
mbedtls_x509_crt *Cert,
|
||||
mbedtls_x509_crt *OtherCerts
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
INT32 Len;
|
||||
mbedtls_x509_crt *TmpCert;
|
||||
|
||||
Len = 0;
|
||||
|
||||
/// Write OtherCerts
|
||||
TmpCert = OtherCerts;
|
||||
while (TmpCert != NULL) {
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_raw_buffer (Ptr, Start, TmpCert->raw.p, TmpCert->raw.len));
|
||||
TmpCert = TmpCert->next;
|
||||
}
|
||||
|
||||
/// Write Cert
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_raw_buffer (Ptr, Start, Cert->raw.p, Cert->raw.len));
|
||||
|
||||
/// Write NextContext
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC));
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
write Pkcs7 Int.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] SerialRaw SerialRaw.
|
||||
@param[in] SerialRawLen Size of SerialRaw.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteInt (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
UINT8 *SerialRaw,
|
||||
INTN SerialRawLen
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
UINT8 *Pt;
|
||||
INT32 Len;
|
||||
|
||||
Len = 0;
|
||||
Pt = SerialRaw + SerialRawLen;
|
||||
while (Pt > SerialRaw) {
|
||||
*--(*Ptr) = *--Pt;
|
||||
Len++;
|
||||
}
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_INTEGER));
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
write Pkcs7 Issuer And SerialNumber.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] Serial Serial.
|
||||
@param[in] SerialLen Size of Serial.
|
||||
@param[in] IssuerRaw IssuerRawLen.
|
||||
@param[in] IssuerRawLen Size of IssuerRawLen.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteIssuerAndSerialNumber (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
UINT8 *Serial,
|
||||
INTN SerialLen,
|
||||
UINT8 *IssuerRaw,
|
||||
INTN IssuerRawLen
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
INT32 Len;
|
||||
|
||||
Len = 0;
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteInt (Ptr, Start, Serial, SerialLen));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_raw_buffer (Ptr, Start, IssuerRaw, IssuerRawLen));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
SignerInfo ::= SEQUENCE {
|
||||
version Version;
|
||||
issuerAndSerialNumber IssuerAndSerialNumber,
|
||||
digestAlgorithm DigestAlgorithmIdentifier,
|
||||
authenticatedAttributes
|
||||
[0] IMPLICIT Attributes OPTIONAL,
|
||||
digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
|
||||
encryptedDigest EncryptedDigest,
|
||||
unauthenticatedAttributes
|
||||
[1] IMPLICIT Attributes OPTIONAL.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] SignerInfo SignerInfo.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteSignerInfo (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
MbedtlsPkcs7SignerInfo *SignerInfo
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
INT32 Len;
|
||||
|
||||
Len = 0;
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_octet_string (Ptr, Start, SignerInfo->Sig.p, SignerInfo->Sig.len));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_algorithm_identifier (Ptr, Start, (CONST CHAR8 *)SignerInfo->SigAlgIdentifier.p, SignerInfo->SigAlgIdentifier.len, 0));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_algorithm_identifier (Ptr, Start, (CONST CHAR8 *)SignerInfo->AlgIdentifier.p, SignerInfo->AlgIdentifier.len, 0));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteIssuerAndSerialNumber (Ptr, Start, SignerInfo->Serial.p, SignerInfo->Serial.len, SignerInfo->IssuerRaw.p, SignerInfo->IssuerRaw.len));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_int (Ptr, Start, SignerInfo->Version));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
write Pkcs7 Signers Info Set.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] SignersSet SignerInfo Set.
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteSignersInfoSet (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
MbedtlsPkcs7SignerInfo *SignersSet
|
||||
)
|
||||
{
|
||||
MbedtlsPkcs7SignerInfo *SignerInfo;
|
||||
INT32 Ret;
|
||||
INT32 Len;
|
||||
|
||||
SignerInfo = SignersSet;
|
||||
Len = 0;
|
||||
|
||||
while (SignerInfo != NULL) {
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteSignerInfo (Ptr, Start, SignerInfo));
|
||||
// move to next
|
||||
SignerInfo = SignerInfo->Next;
|
||||
}
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET));
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
Signed Data Type
|
||||
SignedData ::= SEQUENCE {
|
||||
version Version,
|
||||
digestAlgorithms DigestAlgorithmIdentifiers,
|
||||
contentInfo ContentInfo,
|
||||
certificates
|
||||
[0] IMPLICIT ExtendedCertificatesAndCertificates
|
||||
OPTIONAL,
|
||||
crls
|
||||
[1] IMPLICIT CertificateRevocationLists OPTIONAL,
|
||||
signerInfos SignerInfos }
|
||||
|
||||
DigestAlgorithmIdentifiers ::=
|
||||
SET OF DigestAlgorithmIdentifier
|
||||
|
||||
SignerInfos ::= SET OF SignerInfo.
|
||||
|
||||
@param[in, out] Ptr The reference to the current position pointer.
|
||||
@param[in] Start The start of the buffer, for bounds-checking.
|
||||
@param[in] Pkcs7 MbedtlsPkcs7
|
||||
|
||||
@retval number The number of bytes written to p on success.
|
||||
@retval negative A negative MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
**/
|
||||
STATIC
|
||||
INT32
|
||||
MbedTlsPkcs7WriteDer (
|
||||
UINT8 **Ptr,
|
||||
UINT8 *Start,
|
||||
MbedtlsPkcs7 *Pkcs7
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
INT32 Len;
|
||||
mbedtls_md_type_t DigestAlg[1];
|
||||
|
||||
DigestAlg[0] = MBEDTLS_MD_SHA256;
|
||||
Len = 0;
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteSignersInfoSet (Ptr, Start, &(Pkcs7->SignedData.SignerInfos)));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteCertificates (Ptr, Start, &(Pkcs7->SignedData.Certificates), Pkcs7->SignedData.Certificates.next));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteContentInfo (Ptr, Start, NULL, 0));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, MbedTlsPkcs7WriteDigestAlgorithmSet (Ptr, Start, DigestAlg, 1));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_int (Ptr, Start, Pkcs7->SignedData.Version));
|
||||
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_len (Ptr, Start, Len));
|
||||
EDKII_ASN1_CHK_ADD (Len, mbedtls_asn1_write_tag (Ptr, Start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
|
||||
Syntax Standard, version 1.5". This interface is only intended to be used for
|
||||
application to perform PKCS#7 functionality validation.
|
||||
|
||||
If this interface is not supported, then return FALSE.
|
||||
|
||||
@param[in] PrivateKey Pointer to the PEM-formatted private key data for
|
||||
data signing.
|
||||
@param[in] PrivateKeySize Size of the PEM private key data in bytes.
|
||||
@param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
|
||||
key data.
|
||||
@param[in] InData Pointer to the content to be signed.
|
||||
@param[in] InDataSize Size of InData in bytes.
|
||||
@param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
|
||||
@param[in] OtherCerts Pointer to an optional additional set of certificates to
|
||||
include in the PKCS#7 signedData (e.g. any intermediate
|
||||
CAs in the chain).
|
||||
@param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
|
||||
responsibility to free the buffer with FreePool().
|
||||
@param[out] SignedDataSize Size of SignedData in bytes.
|
||||
|
||||
@retval TRUE PKCS#7 data signing succeeded.
|
||||
@retval FALSE PKCS#7 data signing failed.
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs7Sign (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN CONST UINT8 *KeyPassword,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN UINT8 *SignCert,
|
||||
IN UINT8 *OtherCerts OPTIONAL,
|
||||
OUT UINT8 **SignedData,
|
||||
OUT UINTN *SignedDataSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
INT32 Ret;
|
||||
mbedtls_pk_context Pkey;
|
||||
UINT8 HashValue[SHA256_DIGEST_SIZE];
|
||||
UINT8 Signature[MAX_SIGNATURE_SIZE];
|
||||
UINTN SignatureLen;
|
||||
UINT8 *NewPrivateKey;
|
||||
mbedtls_x509_crt *Crt;
|
||||
|
||||
MbedtlsPkcs7 Pkcs7;
|
||||
MbedtlsPkcs7SignerInfo SignerInfo;
|
||||
UINT8 *Buffer;
|
||||
INTN BufferSize;
|
||||
UINT8 *Ptr;
|
||||
INT32 Len;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((PrivateKey == NULL) || (KeyPassword == NULL) || (InData == NULL) ||
|
||||
(SignCert == NULL) || (SignedData == NULL) || (SignedDataSize == NULL) || (InDataSize > INT_MAX))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BufferSize = 4096;
|
||||
|
||||
SignatureLen = MAX_SIGNATURE_SIZE;
|
||||
Crt = (mbedtls_x509_crt *)SignCert;
|
||||
|
||||
NewPrivateKey = NULL;
|
||||
if (PrivateKey[PrivateKeySize - 1] != 0) {
|
||||
NewPrivateKey = AllocateZeroPool (PrivateKeySize + 1);
|
||||
if (NewPrivateKey == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMem (NewPrivateKey, PrivateKey, PrivateKeySize);
|
||||
NewPrivateKey[PrivateKeySize] = 0;
|
||||
PrivateKeySize++;
|
||||
} else {
|
||||
NewPrivateKey = AllocateZeroPool (PrivateKeySize);
|
||||
if (NewPrivateKey == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMem (NewPrivateKey, PrivateKey, PrivateKeySize);
|
||||
}
|
||||
|
||||
mbedtls_pk_init (&Pkey);
|
||||
Ret = mbedtls_pk_parse_key (
|
||||
&Pkey,
|
||||
NewPrivateKey,
|
||||
PrivateKeySize,
|
||||
KeyPassword,
|
||||
KeyPassword == NULL ? 0 : AsciiStrLen ((CONST CHAR8 *)KeyPassword),
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
if (Ret != 0) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
/// Calculate InData Digest
|
||||
ZeroMem (HashValue, SHA256_DIGEST_SIZE);
|
||||
Status = Sha256HashAll (InData, InDataSize, HashValue);
|
||||
if (!Status) {
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
/// Pk Sign
|
||||
ZeroMem (Signature, MAX_SIGNATURE_SIZE);
|
||||
Ret = mbedtls_pk_sign (
|
||||
&Pkey,
|
||||
MBEDTLS_MD_SHA256,
|
||||
HashValue,
|
||||
SHA256_DIGEST_SIZE,
|
||||
Signature,
|
||||
MAX_SIGNATURE_SIZE,
|
||||
&SignatureLen,
|
||||
MbedtlsRand,
|
||||
NULL
|
||||
);
|
||||
if (Ret != 0) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
ZeroMem (&Pkcs7, sizeof (MbedtlsPkcs7));
|
||||
Pkcs7.SignedData.Version = 1;
|
||||
|
||||
Crt->next = (mbedtls_x509_crt *)OtherCerts;
|
||||
Pkcs7.SignedData.Certificates = *Crt;
|
||||
|
||||
SignerInfo.Next = NULL;
|
||||
SignerInfo.Sig.p = Signature;
|
||||
SignerInfo.Sig.len = SignatureLen;
|
||||
SignerInfo.Version = 1;
|
||||
SignerInfo.AlgIdentifier.p = MbedtlsOidDigestAlgSha256;
|
||||
SignerInfo.AlgIdentifier.len = sizeof (MBEDTLS_OID_DIGEST_ALG_SHA256) - 1;
|
||||
if (mbedtls_pk_get_type (&Pkey) == MBEDTLS_PK_RSA) {
|
||||
SignerInfo.SigAlgIdentifier.p = MbedtlsOidPkcs1Rsa;
|
||||
SignerInfo.SigAlgIdentifier.len = sizeof (MBEDTLS_OID_PKCS1_RSA) - 1;
|
||||
} else {
|
||||
Ret = mbedtls_oid_get_oid_by_sig_alg (MBEDTLS_PK_ECDSA, MBEDTLS_MD_SHA256, (CONST CHAR8 **)&SignerInfo.SigAlgIdentifier.p, &SignerInfo.SigAlgIdentifier.len);
|
||||
if (Ret != 0) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
SignerInfo.Serial = ((mbedtls_x509_crt *)SignCert)->serial;
|
||||
SignerInfo.IssuerRaw = ((mbedtls_x509_crt *)SignCert)->issuer_raw;
|
||||
Pkcs7.SignedData.SignerInfos = SignerInfo;
|
||||
|
||||
Buffer = AllocateZeroPool (BufferSize);
|
||||
if (Buffer == NULL) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
Ptr = Buffer + BufferSize;
|
||||
Len = MbedTlsPkcs7WriteDer (&Ptr, Buffer, &Pkcs7);
|
||||
|
||||
/// Enlarge buffer if buffer is too small
|
||||
while (Len == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) {
|
||||
BufferSize = BufferSize * 2;
|
||||
Ptr = Buffer + BufferSize;
|
||||
FreePool (Buffer);
|
||||
Buffer = AllocateZeroPool (BufferSize);
|
||||
if (Buffer == NULL) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
Ptr = Buffer + BufferSize;
|
||||
Len = MbedTlsPkcs7WriteDer (&Ptr, Buffer, &Pkcs7);
|
||||
}
|
||||
|
||||
if (Len <= 0) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
*SignedData = AllocateZeroPool (Len);
|
||||
if (*SignedData == NULL) {
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
*SignedDataSize = Len;
|
||||
CopyMem (*SignedData, Ptr, Len);
|
||||
Status = TRUE;
|
||||
|
||||
Cleanup:
|
||||
if (&Pkey != NULL) {
|
||||
mbedtls_pk_free (&Pkey);
|
||||
}
|
||||
|
||||
if (NewPrivateKey != NULL) {
|
||||
memset (NewPrivateKey, 0, PrivateKeySize);
|
||||
FreePool (NewPrivateKey);
|
||||
}
|
||||
|
||||
if (Buffer != NULL) {
|
||||
memset (Buffer, 0, BufferSize);
|
||||
FreePool (Buffer);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
113
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7VerifyBase.c
Normal file
113
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7VerifyBase.c
Normal file
@ -0,0 +1,113 @@
|
||||
/** @file
|
||||
Non-runtime specific implementation of PKCS#7 SignedData Verification Wrapper.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/pkcs7.h>
|
||||
|
||||
/**
|
||||
Extracts the attached content from a PKCS#7 signed data if existed. The input signed
|
||||
data could be wrapped in a ContentInfo structure.
|
||||
|
||||
If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
|
||||
then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
|
||||
|
||||
Caution: This function may receive untrusted input. So this function will do
|
||||
basic check for PKCS#7 data structure.
|
||||
|
||||
@param[in] P7Data Pointer to the PKCS#7 signed data to process.
|
||||
@param[in] P7Length Length of the PKCS#7 signed data in bytes.
|
||||
@param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
|
||||
It's caller's responsibility to free the buffer with FreePool().
|
||||
@param[out] ContentSize The size of the extracted content in bytes.
|
||||
|
||||
@retval TRUE The P7Data was correctly formatted for processing.
|
||||
@retval FALSE The P7Data was not correctly formatted for processing.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs7GetAttachedContent (
|
||||
IN CONST UINT8 *P7Data,
|
||||
IN UINTN P7Length,
|
||||
OUT VOID **Content,
|
||||
OUT UINTN *ContentSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 *SignedData;
|
||||
UINTN SignedDataSize;
|
||||
BOOLEAN Wrapped;
|
||||
INTN Ret;
|
||||
mbedtls_pkcs7 Pkcs7;
|
||||
mbedtls_pkcs7_data *MbedtlsContent;
|
||||
|
||||
mbedtls_pkcs7_init (&Pkcs7);
|
||||
|
||||
//
|
||||
// Check input parameter.
|
||||
//
|
||||
if ((P7Data == NULL) || (P7Length > INT_MAX) || (Content == NULL) || (ContentSize == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*Content = NULL;
|
||||
SignedData = NULL;
|
||||
|
||||
Status = WrapPkcs7Data (P7Data, P7Length, &Wrapped, &SignedData, &SignedDataSize);
|
||||
if (!Status || (SignedDataSize > INT_MAX)) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
Status = FALSE;
|
||||
|
||||
Ret = mbedtls_pkcs7_parse_der (&Pkcs7, SignedData, (INT32)SignedDataSize);
|
||||
|
||||
//
|
||||
// The type of Pkcs7 must be signedData
|
||||
//
|
||||
if (Ret != MBEDTLS_PKCS7_SIGNED_DATA) {
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for detached or attached content
|
||||
//
|
||||
MbedtlsContent = &(Pkcs7.signed_data.content);
|
||||
|
||||
if (MbedtlsContent == NULL) {
|
||||
//
|
||||
// No Content supplied for PKCS7 detached signedData
|
||||
//
|
||||
*Content = NULL;
|
||||
*ContentSize = 0;
|
||||
} else {
|
||||
//
|
||||
// Retrieve the attached content in PKCS7 signedData
|
||||
//
|
||||
if ((MbedtlsContent->data.len > 0) && (MbedtlsContent->data.p != NULL)) {
|
||||
*ContentSize = MbedtlsContent->data.len;
|
||||
*Content = AllocateZeroPool (*ContentSize);
|
||||
if (*Content == NULL) {
|
||||
*ContentSize = 0;
|
||||
goto _Exit;
|
||||
}
|
||||
|
||||
CopyMem (*Content, MbedtlsContent->data.p, *ContentSize);
|
||||
}
|
||||
}
|
||||
|
||||
Status = TRUE;
|
||||
|
||||
_Exit:
|
||||
//
|
||||
// Release Resources
|
||||
//
|
||||
mbedtls_pkcs7_free (&Pkcs7);
|
||||
|
||||
return Status;
|
||||
}
|
1354
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7VerifyCommon.c
Normal file
1354
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7VerifyCommon.c
Normal file
File diff suppressed because it is too large
Load Diff
689
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7VerifyEku.c
Normal file
689
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptPkcs7VerifyEku.c
Normal file
@ -0,0 +1,689 @@
|
||||
/** @file
|
||||
This module verifies that Enhanced Key Usages (EKU's) are present within
|
||||
a PKCS7 signature blob using MbedTLS.
|
||||
|
||||
Copyright (C) Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <Base.h>
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/pkcs7.h>
|
||||
#include <mbedtls/asn1write.h>
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 EkuOID[] = { 0x55, 0x1D, 0x25 };
|
||||
|
||||
/*leaf Cert basic_constraints case1: CA: false and CA object is excluded */
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gBasicConstraintsCase1[] = { 0x30, 0x00 };
|
||||
|
||||
/*leaf Cert basic_constraints case2: CA: false */
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gBasicConstraintsCase2[] = { 0x30, 0x06, 0x01, 0x01, 0xFF, 0x02, 0x01, 0x00 };
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gOidBasicConstraints[] = { 0x55, 0x1D, 0x13 };
|
||||
|
||||
/**
|
||||
Find first Extension data match with given OID
|
||||
|
||||
@param[in] Start Pointer to the DER-encoded extensions data
|
||||
@param[in] End extensions data size in bytes
|
||||
@param[in ] Oid OID for match
|
||||
@param[in ] OidSize OID size in bytes
|
||||
@param[out] FindExtensionData output matched extension data.
|
||||
@param[out] FindExtensionDataLen matched extension data size.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
BOOLEAN
|
||||
InternalX509FindExtensionData (
|
||||
UINT8 *Start,
|
||||
UINT8 *End,
|
||||
CONST UINT8 *Oid,
|
||||
UINTN OidSize,
|
||||
UINT8 **FindExtensionData,
|
||||
UINTN *FindExtensionDataLen
|
||||
)
|
||||
{
|
||||
UINT8 *Ptr;
|
||||
UINT8 *ExtensionPtr;
|
||||
UINTN ObjLen;
|
||||
INT32 Ret;
|
||||
BOOLEAN Status;
|
||||
UINTN FindExtensionLen;
|
||||
UINTN HeaderLen;
|
||||
|
||||
/*If no Extension entry match Oid*/
|
||||
Status = FALSE;
|
||||
Ptr = Start;
|
||||
|
||||
Ret = 0;
|
||||
|
||||
while (TRUE) {
|
||||
//
|
||||
// Extension ::= SEQUENCE {
|
||||
// extnID OBJECT IDENTIFIER,
|
||||
// critical BOOLEAN DEFAULT FALSE,
|
||||
// extnValue OCTET STRING }
|
||||
//
|
||||
ExtensionPtr = Ptr;
|
||||
Ret = mbedtls_asn1_get_tag (
|
||||
&Ptr,
|
||||
End,
|
||||
&ObjLen,
|
||||
MBEDTLS_ASN1_CONSTRUCTED |
|
||||
MBEDTLS_ASN1_SEQUENCE
|
||||
);
|
||||
if (Ret == 0) {
|
||||
HeaderLen = (UINTN)(Ptr - ExtensionPtr);
|
||||
FindExtensionLen = ObjLen;
|
||||
/* Get Object Identifier*/
|
||||
Ret = mbedtls_asn1_get_tag (
|
||||
&Ptr,
|
||||
End,
|
||||
&ObjLen,
|
||||
MBEDTLS_ASN1_OID
|
||||
);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((Ret == 0) && !CompareMem (Ptr, Oid, OidSize)) {
|
||||
Ptr += ObjLen;
|
||||
|
||||
Ret = mbedtls_asn1_get_tag (
|
||||
&Ptr,
|
||||
End,
|
||||
&ObjLen,
|
||||
MBEDTLS_ASN1_BOOLEAN
|
||||
);
|
||||
if (Ret == 0) {
|
||||
Ptr += ObjLen;
|
||||
}
|
||||
|
||||
Ret = mbedtls_asn1_get_tag (
|
||||
&Ptr,
|
||||
End,
|
||||
&ObjLen,
|
||||
MBEDTLS_ASN1_OCTET_STRING
|
||||
);
|
||||
} else {
|
||||
Ret = 1;
|
||||
}
|
||||
|
||||
if (Ret == 0) {
|
||||
*FindExtensionData = Ptr;
|
||||
*FindExtensionDataLen = ObjLen;
|
||||
Status = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* move to next*/
|
||||
Ptr = ExtensionPtr + HeaderLen + FindExtensionLen;
|
||||
Ret = 0;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieve Extension data from one X.509 certificate.
|
||||
|
||||
@param[in] Cert Pointer to the X509 certificate.
|
||||
@param[in] Oid Object identifier buffer
|
||||
@param[in] OidSize Object identifier buffer size
|
||||
@param[out] ExtensionData Extension bytes.
|
||||
@param[in, out] ExtensionDataSize Extension bytes size.
|
||||
|
||||
@retval RETURN_SUCCESS The certificate Extension data retrieved successfully.
|
||||
@retval RETURN_INVALID_PARAMETER If Cert is NULL.
|
||||
If ExtensionDataSize is NULL.
|
||||
If ExtensionData is not NULL and *ExtensionDataSize is 0.
|
||||
If Certificate is invalid.
|
||||
@retval RETURN_NOT_FOUND If no Extension entry match Oid.
|
||||
@retval RETURN_BUFFER_TOO_SMALL If the ExtensionData is NULL. The required buffer size
|
||||
is returned in the ExtensionDataSize parameter.
|
||||
@retval RETURN_UNSUPPORTED The operation is not supported.
|
||||
**/
|
||||
STATIC
|
||||
BOOLEAN
|
||||
GetExtensionData (
|
||||
CONST mbedtls_x509_crt *Cert,
|
||||
CONST UINT8 *Oid,
|
||||
UINTN OidSize,
|
||||
UINT8 *ExtensionData,
|
||||
UINTN *ExtensionDataSize
|
||||
)
|
||||
{
|
||||
CONST mbedtls_x509_crt *Crt;
|
||||
INT32 Ret;
|
||||
BOOLEAN Status;
|
||||
UINT8 *Ptr;
|
||||
UINT8 *End;
|
||||
UINTN ObjLen;
|
||||
|
||||
Ptr = NULL;
|
||||
End = NULL;
|
||||
ObjLen = 0;
|
||||
|
||||
if ((Cert == NULL) || (Oid == NULL) || (OidSize == 0) ||
|
||||
(ExtensionDataSize == NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = FALSE;
|
||||
|
||||
Crt = Cert;
|
||||
|
||||
Ptr = Crt->v3_ext.p;
|
||||
End = Crt->v3_ext.p + Crt->v3_ext.len;
|
||||
Ret = mbedtls_asn1_get_tag (
|
||||
&Ptr,
|
||||
End,
|
||||
&ObjLen,
|
||||
MBEDTLS_ASN1_CONSTRUCTED |
|
||||
MBEDTLS_ASN1_SEQUENCE
|
||||
);
|
||||
|
||||
if (Ret == 0) {
|
||||
Status = InternalX509FindExtensionData (
|
||||
Ptr,
|
||||
End,
|
||||
Oid,
|
||||
OidSize,
|
||||
&Ptr,
|
||||
&ObjLen
|
||||
);
|
||||
}
|
||||
|
||||
if (Status) {
|
||||
if (*ExtensionDataSize < ObjLen) {
|
||||
*ExtensionDataSize = ObjLen;
|
||||
Status = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
if (Oid != NULL) {
|
||||
if (ExtensionData == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMem (ExtensionData, Ptr, ObjLen);
|
||||
}
|
||||
|
||||
*ExtensionDataSize = ObjLen;
|
||||
} else {
|
||||
*ExtensionDataSize = 0;
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if the specified EKU represented in ASN1 form is present
|
||||
in a given certificate.
|
||||
|
||||
@param[in] Cert The certificate to check.
|
||||
@param[in] EKU The EKU to look for.
|
||||
@param[in] EkuLen The size of EKU.
|
||||
|
||||
@retval EFI_SUCCESS We successfully identified the signing type.
|
||||
@retval EFI_INVALID_PARAMETER A parameter was invalid.
|
||||
@retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
IsEkuInCertificate (
|
||||
IN CONST mbedtls_x509_crt *Cert,
|
||||
IN UINT8 *EKU,
|
||||
IN UINTN EkuLen
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
BOOLEAN Ret;
|
||||
UINT8 *Buffer;
|
||||
UINTN Index;
|
||||
UINTN Len;
|
||||
|
||||
if ((Cert == NULL) || (EKU == NULL)) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
return Status;
|
||||
}
|
||||
|
||||
Len = 0;
|
||||
Buffer = NULL;
|
||||
Ret = GetExtensionData (
|
||||
Cert,
|
||||
(CONST UINT8 *)EkuOID,
|
||||
sizeof (EkuOID),
|
||||
NULL,
|
||||
&Len
|
||||
);
|
||||
if (Len == 0) {
|
||||
Status = EFI_NOT_FOUND;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Buffer = AllocateZeroPool (Len);
|
||||
if (Buffer == NULL) {
|
||||
Status = EFI_NOT_FOUND;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Ret = GetExtensionData (
|
||||
Cert,
|
||||
(CONST UINT8 *)EkuOID,
|
||||
sizeof (EkuOID),
|
||||
Buffer,
|
||||
&Len
|
||||
);
|
||||
|
||||
if ((Len == 0) || (!Ret)) {
|
||||
Status = EFI_NOT_FOUND;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Status = EFI_NOT_FOUND;
|
||||
/*find the spdm hardware identity OID*/
|
||||
for (Index = 0; Index <= Len - EkuLen; Index++) {
|
||||
if (!CompareMem (Buffer + Index, EKU, EkuLen)) {
|
||||
// check sub EKU
|
||||
if (Index == Len - EkuLen) {
|
||||
Status = EFI_SUCCESS;
|
||||
break;
|
||||
// Ensure that the OID is complete
|
||||
} else if (Buffer[Index + EkuLen] == 0x06) {
|
||||
Status = EFI_SUCCESS;
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
if (Buffer != NULL) {
|
||||
FreePool (Buffer);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Get OID from txt.
|
||||
|
||||
@param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
|
||||
required EKUs that must be present in the signature.
|
||||
@param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
|
||||
@param[in,out] CheckOid OID.
|
||||
@param[out] OidLen The size of OID.
|
||||
|
||||
**/
|
||||
VOID
|
||||
GetOidFromTxt (
|
||||
IN CONST CHAR8 *RequiredEKUs,
|
||||
IN UINTN RequiredEKUsSize,
|
||||
IN OUT UINT8 *CheckOid,
|
||||
OUT UINT8 *OidLen
|
||||
)
|
||||
{
|
||||
UINT8 *Ptr;
|
||||
UINT16 Index;
|
||||
UINT32 Data;
|
||||
UINT8 OidIndex;
|
||||
UINTN EKUsSize;
|
||||
|
||||
EKUsSize = RequiredEKUsSize;
|
||||
// https://learn.microsoft.com/en-us/windows/win32/seccertenroll/about-object-identifier?redirectedfrom=MSDN
|
||||
CheckOid[0] = (UINT8)((RequiredEKUs[0] - '0') * 40 + (RequiredEKUs[2] - '0'));
|
||||
|
||||
EKUsSize = EKUsSize - 4;
|
||||
Ptr = (UINT8 *)(RequiredEKUs + 4);
|
||||
|
||||
OidIndex = 1;
|
||||
|
||||
while (EKUsSize) {
|
||||
Index = 0;
|
||||
Data = 0;
|
||||
|
||||
while ((*Ptr != '.') && (*Ptr != '\0')) {
|
||||
Index++;
|
||||
Ptr++;
|
||||
EKUsSize--;
|
||||
}
|
||||
|
||||
while (Index) {
|
||||
Data = 10 * Data + (*(Ptr - Index) - '0');
|
||||
Index--;
|
||||
}
|
||||
|
||||
if (EKUsSize != 0) {
|
||||
Ptr++;
|
||||
EKUsSize--;
|
||||
}
|
||||
|
||||
if (Data < 128) {
|
||||
CheckOid[OidIndex] = (UINT8)Data;
|
||||
OidIndex++;
|
||||
} else {
|
||||
CheckOid[OidIndex + 1] = (UINT8)(Data & 0xFF);
|
||||
CheckOid[OidIndex] = (UINT8)(((((Data & 0xFF00) << 1) | 0x8000) >> 8) & 0xFF);
|
||||
OidIndex = OidIndex + 2;
|
||||
}
|
||||
}
|
||||
|
||||
*OidLen = OidIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
Verify the Cert is signer cert
|
||||
|
||||
@param[in] Start Pointer to the DER-encoded certificate data Start.
|
||||
@param[in] End Pointer to the DER-encoded certificate data End.
|
||||
|
||||
@retval true verify pass
|
||||
@retval false verify fail
|
||||
**/
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsCertSignerCert (
|
||||
UINT8 *Start,
|
||||
UINT8 *End
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 *Buffer;
|
||||
UINTN Len;
|
||||
mbedtls_x509_crt Cert;
|
||||
UINTN ObjLen;
|
||||
|
||||
mbedtls_x509_crt_init (&Cert);
|
||||
|
||||
ObjLen = End - Start;
|
||||
|
||||
if (mbedtls_x509_crt_parse_der (&Cert, Start, ObjLen) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Len = 0;
|
||||
Buffer = NULL;
|
||||
Status = GetExtensionData (
|
||||
&Cert,
|
||||
(CONST UINT8 *)gOidBasicConstraints,
|
||||
sizeof (gOidBasicConstraints),
|
||||
NULL,
|
||||
&Len
|
||||
);
|
||||
if (Len == 0) {
|
||||
/* basic constraints is not present in Cert */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Buffer = AllocateZeroPool (Len);
|
||||
if (Buffer == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = GetExtensionData (
|
||||
&Cert,
|
||||
(CONST UINT8 *)gOidBasicConstraints,
|
||||
sizeof (gOidBasicConstraints),
|
||||
Buffer,
|
||||
&Len
|
||||
);
|
||||
|
||||
if (Len == 0) {
|
||||
/* basic constraints is not present in Cert */
|
||||
Status = TRUE;
|
||||
goto Exit;
|
||||
} else if (!Status) {
|
||||
Status = FALSE;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if ((Len == sizeof (gBasicConstraintsCase1)) &&
|
||||
(!CompareMem (Buffer, gBasicConstraintsCase1, sizeof (gBasicConstraintsCase1))))
|
||||
{
|
||||
Status = TRUE;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if ((Len == sizeof (gBasicConstraintsCase2)) &&
|
||||
(!CompareMem (Buffer, gBasicConstraintsCase2, sizeof (gBasicConstraintsCase2))))
|
||||
{
|
||||
Status = TRUE;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Status = FALSE;
|
||||
|
||||
Exit:
|
||||
mbedtls_x509_crt_free (&Cert);
|
||||
|
||||
if (Buffer != NULL) {
|
||||
FreePool (Buffer);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if the specified EKUs are present in a signing certificate.
|
||||
|
||||
@param[in] SignerCert The certificate to check.
|
||||
@param[in] RequiredEKUs The EKUs to look for.
|
||||
@param[in] RequiredEKUsSize The number of EKUs
|
||||
@param[in] RequireAllPresent If TRUE, then all the specified EKUs
|
||||
must be present in the certificate.
|
||||
|
||||
@retval EFI_SUCCESS We successfully identified the signing type.
|
||||
@retval EFI_INVALID_PARAMETER A parameter was invalid.
|
||||
@retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
CheckEKUs (
|
||||
IN CONST mbedtls_x509_crt *SignerCert,
|
||||
IN CONST CHAR8 *RequiredEKUs[],
|
||||
IN CONST UINT32 RequiredEKUsSize,
|
||||
IN BOOLEAN RequireAllPresent
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 NumEkusFound;
|
||||
UINT32 Index;
|
||||
UINT8 *EKU;
|
||||
UINTN EkuLen;
|
||||
UINT8 CheckOid[20];
|
||||
UINT8 OidLen;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
NumEkusFound = 0;
|
||||
|
||||
if ((SignerCert == NULL) || (RequiredEKUs == NULL) || (RequiredEKUsSize == 0)) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < RequiredEKUsSize; Index++) {
|
||||
//
|
||||
// Finding required EKU in Cert.
|
||||
//
|
||||
GetOidFromTxt (RequiredEKUs[Index], strlen (RequiredEKUs[Index]), CheckOid, &OidLen);
|
||||
|
||||
EKU = CheckOid;
|
||||
EkuLen = OidLen;
|
||||
|
||||
Status = IsEkuInCertificate (SignerCert, EKU, EkuLen);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
NumEkusFound++;
|
||||
if (!RequireAllPresent) {
|
||||
//
|
||||
// Found at least one, so we are done.
|
||||
//
|
||||
goto Exit;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// Fail to find Eku in Cert
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
if (RequireAllPresent &&
|
||||
(NumEkusFound == RequiredEKUsSize))
|
||||
{
|
||||
//
|
||||
// Found all required EKUs in certificate.
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
This function receives a PKCS#7 formatted signature blob,
|
||||
looks for the EKU SEQUENCE blob, and if found then looks
|
||||
for all the required EKUs. This function was created so that
|
||||
the Surface team can cut down on the number of Certificate
|
||||
Authorities (CA's) by checking EKU's on leaf signers for
|
||||
a specific product. This prevents one product's certificate
|
||||
from signing another product's firmware or unlock blobs.
|
||||
|
||||
Note that this function does not validate the certificate chain.
|
||||
That needs to be done before using this function.
|
||||
|
||||
@param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
|
||||
containing the content block with both the signature,
|
||||
the signer's certificate, and any necessary intermediate
|
||||
certificates.
|
||||
@param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
|
||||
@param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
|
||||
required EKUs that must be present in the signature.
|
||||
@param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
|
||||
@param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
|
||||
must be present in the leaf signer. If it is
|
||||
FALSE, then we will succeed if we find any
|
||||
of the specified EKU's.
|
||||
|
||||
@retval EFI_SUCCESS The required EKUs were found in the signature.
|
||||
@retval EFI_INVALID_PARAMETER A parameter was invalid.
|
||||
@retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VerifyEKUsInPkcs7Signature (
|
||||
IN CONST UINT8 *Pkcs7Signature,
|
||||
IN CONST UINT32 SignatureSize,
|
||||
IN CONST CHAR8 *RequiredEKUs[],
|
||||
IN CONST UINT32 RequiredEKUsSize,
|
||||
IN BOOLEAN RequireAllPresent
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
mbedtls_x509_crt Cert;
|
||||
UINT8 *Ptr;
|
||||
UINT8 *End;
|
||||
INT32 Len;
|
||||
UINTN ObjLen;
|
||||
UINT8 *OldEnd;
|
||||
|
||||
//
|
||||
// Check input parameter.
|
||||
//
|
||||
if ((RequiredEKUs == NULL) || (Pkcs7Signature == NULL)) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
return Status;
|
||||
}
|
||||
|
||||
mbedtls_x509_crt_init (&Cert);
|
||||
|
||||
Ptr = (UINT8 *)(UINTN)Pkcs7Signature;
|
||||
Len = (UINT32)SignatureSize;
|
||||
End = Ptr + Len;
|
||||
|
||||
// Cert
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// tbscert
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// signature algo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// signature
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
OldEnd = Ptr;
|
||||
// Cert
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
End = Ptr + ObjLen;
|
||||
|
||||
// leaf Cert
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
while ((Ptr != End) && (Ptr < End)) {
|
||||
if (IsCertSignerCert (OldEnd, Ptr)) {
|
||||
break;
|
||||
}
|
||||
|
||||
OldEnd = Ptr;
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
}
|
||||
|
||||
if (Ptr != End) {
|
||||
return FALSE;
|
||||
} else {
|
||||
Ptr = End - ObjLen;
|
||||
}
|
||||
|
||||
// leaf Cert
|
||||
ObjLen += Ptr - OldEnd;
|
||||
Ptr = OldEnd;
|
||||
|
||||
if (mbedtls_x509_crt_parse_der (&Cert, Ptr, ObjLen) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = CheckEKUs (&Cert, RequiredEKUs, RequiredEKUsSize, RequireAllPresent);
|
||||
if (Status != EFI_SUCCESS) {
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Exit:
|
||||
//
|
||||
// Release Resources
|
||||
//
|
||||
mbedtls_x509_crt_free (&Cert);
|
||||
|
||||
return Status;
|
||||
}
|
352
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptRsaExt.c
Normal file
352
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptRsaExt.c
Normal file
@ -0,0 +1,352 @@
|
||||
/** @file
|
||||
RSA Asymmetric Cipher Wrapper Implementation over MbedTLS.
|
||||
|
||||
This file implements following APIs which provide more capabilities for RSA:
|
||||
1) RsaGetKey
|
||||
2) RsaGenerateKey
|
||||
3) RsaCheckKey
|
||||
4) RsaPkcs1Sign
|
||||
|
||||
RFC 8017 - PKCS #1: RSA Cryptography Specifications Version 2.2
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/rsa.h>
|
||||
|
||||
/**
|
||||
Gets the tag-designated RSA key component from the established RSA context.
|
||||
|
||||
This function retrieves the tag-designated RSA key component from the
|
||||
established RSA context as a non-negative integer (octet string format
|
||||
represented in RSA PKCS#1).
|
||||
If specified key component has not been set or has been cleared, then returned
|
||||
BnSize is set to 0.
|
||||
If the BigNumber buffer is too small to hold the contents of the key, FALSE
|
||||
is returned and BnSize is set to the required buffer size to obtain the key.
|
||||
|
||||
If RsaContext is NULL, then return FALSE.
|
||||
If BnSize is NULL, then return FALSE.
|
||||
If BnSize is large enough but BigNumber is NULL, then return FALSE.
|
||||
|
||||
@param[in, out] RsaContext Pointer to RSA context being set.
|
||||
@param[in] KeyTag Tag of RSA key component being set.
|
||||
@param[out] BigNumber Pointer to octet integer buffer.
|
||||
@param[in, out] BnSize On input, the size of big number buffer in bytes.
|
||||
On output, the size of data returned in big number buffer in bytes.
|
||||
|
||||
@retval TRUE RSA key component was retrieved successfully.
|
||||
@retval FALSE Invalid RSA key component tag.
|
||||
@retval FALSE BnSize is too small.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaGetKey (
|
||||
IN OUT VOID *RsaContext,
|
||||
IN RSA_KEY_TAG KeyTag,
|
||||
OUT UINT8 *BigNumber,
|
||||
IN OUT UINTN *BnSize
|
||||
)
|
||||
{
|
||||
mbedtls_rsa_context *RsaKey;
|
||||
INT32 Ret;
|
||||
mbedtls_mpi Value;
|
||||
UINTN Size;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((RsaContext == NULL) || (*BnSize > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Init mbedtls_mpi
|
||||
//
|
||||
mbedtls_mpi_init (&Value);
|
||||
Size = *BnSize;
|
||||
*BnSize = 0;
|
||||
|
||||
RsaKey = (mbedtls_rsa_context *)RsaContext;
|
||||
|
||||
switch (KeyTag) {
|
||||
case RsaKeyN:
|
||||
Ret = mbedtls_rsa_export (RsaKey, &Value, NULL, NULL, NULL, NULL);
|
||||
break;
|
||||
case RsaKeyE:
|
||||
Ret = mbedtls_rsa_export (RsaKey, NULL, NULL, NULL, NULL, &Value);
|
||||
break;
|
||||
case RsaKeyD:
|
||||
Ret = mbedtls_rsa_export (RsaKey, NULL, NULL, NULL, &Value, NULL);
|
||||
break;
|
||||
case RsaKeyQ:
|
||||
Ret = mbedtls_rsa_export (RsaKey, NULL, NULL, &Value, NULL, NULL);
|
||||
break;
|
||||
case RsaKeyP:
|
||||
Ret = mbedtls_rsa_export (RsaKey, NULL, &Value, NULL, NULL, NULL);
|
||||
break;
|
||||
case RsaKeyDp:
|
||||
case RsaKeyDq:
|
||||
case RsaKeyQInv:
|
||||
default:
|
||||
Ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Ret != 0) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
if (mbedtls_mpi_size (&Value) == 0) {
|
||||
Ret = 0;
|
||||
goto End;
|
||||
}
|
||||
|
||||
*BnSize = Size;
|
||||
|
||||
Size = mbedtls_mpi_size (&Value);
|
||||
if (*BnSize < Size) {
|
||||
Ret = 1;
|
||||
*BnSize = Size;
|
||||
goto End;
|
||||
}
|
||||
|
||||
if (BigNumber == NULL) {
|
||||
Ret = 0;
|
||||
*BnSize = Size;
|
||||
goto End;
|
||||
}
|
||||
|
||||
if ((BigNumber != NULL) && (Ret == 0)) {
|
||||
Ret = mbedtls_mpi_write_binary (&Value, BigNumber, Size);
|
||||
*BnSize = Size;
|
||||
}
|
||||
|
||||
End:
|
||||
mbedtls_mpi_free (&Value);
|
||||
return Ret == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Generates RSA key components.
|
||||
|
||||
This function generates RSA key components. It takes RSA public exponent Pe and
|
||||
length in bits of RSA modulus N as input, and generates all key components.
|
||||
If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
|
||||
|
||||
Before this function can be invoked, pseudorandom number generator must be correctly
|
||||
initialized by RandomSeed().
|
||||
|
||||
If RsaContext is NULL, then return FALSE.
|
||||
|
||||
@param[in, out] RsaContext Pointer to RSA context being set.
|
||||
@param[in] ModulusLength Length of RSA modulus N in bits.
|
||||
@param[in] PublicExponent Pointer to RSA public exponent.
|
||||
@param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
|
||||
|
||||
@retval TRUE RSA key component was generated successfully.
|
||||
@retval FALSE Invalid RSA key component tag.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaGenerateKey (
|
||||
IN OUT VOID *RsaContext,
|
||||
IN UINTN ModulusLength,
|
||||
IN CONST UINT8 *PublicExponent,
|
||||
IN UINTN PublicExponentSize
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
mbedtls_rsa_context *Rsa;
|
||||
INT32 Pe;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((RsaContext == NULL) || (ModulusLength > INT_MAX) || (PublicExponentSize > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Rsa = (mbedtls_rsa_context *)RsaContext;
|
||||
|
||||
if (PublicExponent == NULL) {
|
||||
Pe = 0x10001;
|
||||
} else {
|
||||
if (PublicExponentSize == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch (PublicExponentSize) {
|
||||
case 1:
|
||||
Pe = PublicExponent[0];
|
||||
break;
|
||||
case 2:
|
||||
Pe = PublicExponent[0] << 8 | PublicExponent[1];
|
||||
break;
|
||||
case 3:
|
||||
Pe = PublicExponent[0] << 16 | PublicExponent[1] << 8 |
|
||||
PublicExponent[2];
|
||||
break;
|
||||
case 4:
|
||||
Pe = PublicExponent[0] << 24 | PublicExponent[1] << 16 |
|
||||
PublicExponent[2] << 8 | PublicExponent[3];
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_gen_key (
|
||||
Rsa,
|
||||
MbedtlsRand,
|
||||
NULL,
|
||||
(UINT32)ModulusLength,
|
||||
Pe
|
||||
);
|
||||
|
||||
return Ret == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Validates key components of RSA context.
|
||||
NOTE: This function performs integrity checks on all the RSA key material, so
|
||||
the RSA key structure must contain all the private key data.
|
||||
|
||||
This function validates key components of RSA context in following aspects:
|
||||
- Whether p is a prime
|
||||
- Whether q is a prime
|
||||
- Whether n = p * q
|
||||
- Whether d*e = 1 mod lcm(p-1,q-1)
|
||||
|
||||
If RsaContext is NULL, then return FALSE.
|
||||
|
||||
@param[in] RsaContext Pointer to RSA context to check.
|
||||
|
||||
@retval TRUE RSA key components are valid.
|
||||
@retval FALSE RSA key components are not valid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaCheckKey (
|
||||
IN VOID *RsaContext
|
||||
)
|
||||
{
|
||||
if (RsaContext == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UINT32 Ret;
|
||||
|
||||
Ret = mbedtls_rsa_complete (RsaContext);
|
||||
if (Ret == 0) {
|
||||
Ret = mbedtls_rsa_check_privkey (RsaContext);
|
||||
}
|
||||
|
||||
return Ret == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
|
||||
|
||||
This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
|
||||
RSA PKCS#1.
|
||||
If the Signature buffer is too small to hold the contents of signature, FALSE
|
||||
is returned and SigSize is set to the required buffer size to obtain the signature.
|
||||
|
||||
If RsaContext is NULL, then return FALSE.
|
||||
If MessageHash is NULL, then return FALSE.
|
||||
If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-384 or SHA-512 digest, then return FALSE.
|
||||
If SigSize is large enough but Signature is NULL, then return FALSE.
|
||||
|
||||
@param[in] RsaContext Pointer to RSA context for signature generation.
|
||||
@param[in] MessageHash Pointer to octet message hash to be signed.
|
||||
@param[in] HashSize Size of the message hash in bytes.
|
||||
@param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
|
||||
@param[in, out] SigSize On input, the size of Signature buffer in bytes.
|
||||
On output, the size of data returned in Signature buffer in bytes.
|
||||
|
||||
@retval TRUE Signature successfully generated in PKCS1-v1_5.
|
||||
@retval FALSE Signature generation failed.
|
||||
@retval FALSE SigSize is too small.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaPkcs1Sign (
|
||||
IN VOID *RsaContext,
|
||||
IN CONST UINT8 *MessageHash,
|
||||
IN UINTN HashSize,
|
||||
OUT UINT8 *Signature,
|
||||
IN OUT UINTN *SigSize
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
mbedtls_md_type_t MdAlg;
|
||||
|
||||
if ((RsaContext == NULL) || (MessageHash == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_rsa_complete ((mbedtls_rsa_context *)RsaContext) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch (HashSize) {
|
||||
#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
|
||||
case SHA1_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA1;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SHA256_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA256;
|
||||
break;
|
||||
|
||||
case SHA384_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA384;
|
||||
break;
|
||||
|
||||
case SHA512_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA512;
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_rsa_get_len (RsaContext) > *SigSize) {
|
||||
*SigSize = mbedtls_rsa_get_len (RsaContext);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Signature == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V15, MdAlg);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_pkcs1_sign (
|
||||
RsaContext,
|
||||
MbedtlsRand,
|
||||
NULL,
|
||||
MdAlg,
|
||||
(UINT32)HashSize,
|
||||
MessageHash,
|
||||
Signature
|
||||
);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*SigSize = mbedtls_rsa_get_len (RsaContext);
|
||||
return TRUE;
|
||||
}
|
@ -11,6 +11,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/rsa.h>
|
||||
#include <mbedtls/sha256.h>
|
||||
#include <mbedtls/sha512.h>
|
||||
|
||||
/**
|
||||
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
|
||||
@ -43,11 +45,8 @@ RsaPssVerify (
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
mbedtls_md_type_t md_alg;
|
||||
mbedtls_md_type_t MdAlg;
|
||||
UINT8 HashValue[SHA512_DIGEST_SIZE];
|
||||
BOOLEAN Status;
|
||||
UINTN ShaCtxSize;
|
||||
VOID *ShaCtx;
|
||||
mbedtls_rsa_context *RsaKey;
|
||||
|
||||
if (RsaContext == NULL) {
|
||||
@ -75,78 +74,27 @@ RsaPssVerify (
|
||||
|
||||
switch (DigestLen) {
|
||||
case SHA256_DIGEST_SIZE:
|
||||
md_alg = MBEDTLS_MD_SHA256;
|
||||
ShaCtxSize = Sha256GetContextSize ();
|
||||
ShaCtx = AllocateZeroPool (ShaCtxSize);
|
||||
|
||||
Status = Sha256Init (ShaCtx);
|
||||
if (!Status) {
|
||||
MdAlg = MBEDTLS_MD_SHA256;
|
||||
if (mbedtls_sha256 (Message, MsgSize, HashValue, FALSE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = Sha256Update (ShaCtx, Message, MsgSize);
|
||||
if (!Status) {
|
||||
FreePool (ShaCtx);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = Sha256Final (ShaCtx, HashValue);
|
||||
if (!Status) {
|
||||
FreePool (ShaCtx);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FreePool (ShaCtx);
|
||||
break;
|
||||
|
||||
case SHA384_DIGEST_SIZE:
|
||||
md_alg = MBEDTLS_MD_SHA384;
|
||||
ShaCtxSize = Sha384GetContextSize ();
|
||||
ShaCtx = AllocateZeroPool (ShaCtxSize);
|
||||
|
||||
Status = Sha384Init (ShaCtx);
|
||||
if (!Status) {
|
||||
MdAlg = MBEDTLS_MD_SHA384;
|
||||
if (mbedtls_sha512 (Message, MsgSize, HashValue, TRUE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = Sha384Update (ShaCtx, Message, MsgSize);
|
||||
if (!Status) {
|
||||
FreePool (ShaCtx);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = Sha384Final (ShaCtx, HashValue);
|
||||
if (!Status) {
|
||||
FreePool (ShaCtx);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FreePool (ShaCtx);
|
||||
break;
|
||||
|
||||
case SHA512_DIGEST_SIZE:
|
||||
md_alg = MBEDTLS_MD_SHA512;
|
||||
ShaCtxSize = Sha512GetContextSize ();
|
||||
ShaCtx = AllocateZeroPool (ShaCtxSize);
|
||||
|
||||
Status = Sha512Init (ShaCtx);
|
||||
if (!Status) {
|
||||
MdAlg = MBEDTLS_MD_SHA512;
|
||||
if (mbedtls_sha512 (Message, MsgSize, HashValue, FALSE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = Sha512Update (ShaCtx, Message, MsgSize);
|
||||
if (!Status) {
|
||||
FreePool (ShaCtx);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = Sha512Final (ShaCtx, HashValue);
|
||||
if (!Status) {
|
||||
FreePool (ShaCtx);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FreePool (ShaCtx);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -157,11 +105,11 @@ RsaPssVerify (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V21, md_alg);
|
||||
mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V21, MdAlg);
|
||||
|
||||
Ret = mbedtls_rsa_rsassa_pss_verify (
|
||||
RsaContext,
|
||||
md_alg,
|
||||
MdAlg,
|
||||
(UINT32)DigestLen,
|
||||
HashValue,
|
||||
Signature
|
||||
|
140
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptRsaPssSign.c
Normal file
140
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptRsaPssSign.c
Normal file
@ -0,0 +1,140 @@
|
||||
/** @file
|
||||
RSA PSS Asymmetric Cipher Wrapper Implementation over MbedTLS.
|
||||
|
||||
This file implements following APIs which provide basic capabilities for RSA:
|
||||
1) RsaPssSign
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/rsa.h>
|
||||
#include <mbedtls/sha256.h>
|
||||
#include <mbedtls/sha512.h>
|
||||
|
||||
/**
|
||||
Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.
|
||||
|
||||
This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
|
||||
RFC 8017.
|
||||
Mask generation function is the same as the message digest algorithm.
|
||||
If the Signature buffer is too small to hold the contents of signature, FALSE
|
||||
is returned and SigSize is set to the required buffer size to obtain the signature.
|
||||
|
||||
If RsaContext is NULL, then return FALSE.
|
||||
If Message is NULL, then return FALSE.
|
||||
If MsgSize is zero or > INT_MAX, then return FALSE.
|
||||
If DigestLen is NOT 32, 48 or 64, return FALSE.
|
||||
If SaltLen is not equal to DigestLen, then return FALSE.
|
||||
If SigSize is large enough but Signature is NULL, then return FALSE.
|
||||
If this interface is not supported, then return FALSE.
|
||||
|
||||
@param[in] RsaContext Pointer to RSA context for signature generation.
|
||||
@param[in] Message Pointer to octet message to be signed.
|
||||
@param[in] MsgSize Size of the message in bytes.
|
||||
@param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
|
||||
@param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
|
||||
@param[out] Signature Pointer to buffer to receive RSA PSS signature.
|
||||
@param[in, out] SigSize On input, the size of Signature buffer in bytes.
|
||||
On output, the size of data returned in Signature buffer in bytes.
|
||||
|
||||
@retval TRUE Signature successfully generated in RSASSA-PSS.
|
||||
@retval FALSE Signature generation failed.
|
||||
@retval FALSE SigSize is too small.
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaPssSign (
|
||||
IN VOID *RsaContext,
|
||||
IN CONST UINT8 *Message,
|
||||
IN UINTN MsgSize,
|
||||
IN UINT16 DigestLen,
|
||||
IN UINT16 SaltLen,
|
||||
OUT UINT8 *Signature,
|
||||
IN OUT UINTN *SigSize
|
||||
)
|
||||
{
|
||||
INT32 Ret;
|
||||
mbedtls_md_type_t MdAlg;
|
||||
UINT8 HashValue[SHA512_DIGEST_SIZE];
|
||||
|
||||
if (RsaContext == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_rsa_complete ((mbedtls_rsa_context *)RsaContext) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((Message == NULL) || (MsgSize == 0) || (MsgSize > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (SaltLen != DigestLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ZeroMem (HashValue, DigestLen);
|
||||
|
||||
switch (DigestLen) {
|
||||
case SHA256_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA256;
|
||||
if (mbedtls_sha256 (Message, MsgSize, HashValue, FALSE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SHA384_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA384;
|
||||
if (mbedtls_sha512 (Message, MsgSize, HashValue, TRUE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SHA512_DIGEST_SIZE:
|
||||
MdAlg = MBEDTLS_MD_SHA512;
|
||||
if (mbedtls_sha512 (Message, MsgSize, HashValue, FALSE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Signature == NULL) {
|
||||
//
|
||||
// If Signature is NULL, return safe SignatureSize
|
||||
//
|
||||
*SigSize = MBEDTLS_MPI_MAX_SIZE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V21, MdAlg);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = mbedtls_rsa_rsassa_pss_sign (
|
||||
RsaContext,
|
||||
MbedtlsRand,
|
||||
NULL,
|
||||
MdAlg,
|
||||
(UINT32)DigestLen,
|
||||
HashValue,
|
||||
Signature
|
||||
);
|
||||
if (Ret != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*SigSize = ((mbedtls_rsa_context *)RsaContext)->len;
|
||||
return TRUE;
|
||||
}
|
381
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptTs.c
Normal file
381
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptTs.c
Normal file
@ -0,0 +1,381 @@
|
||||
/** @file
|
||||
RFC3161 Timestamp Countersignature Verification Wrapper Implementation which does
|
||||
not provide real capabilities.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <mbedtls/asn1.h>
|
||||
|
||||
//
|
||||
// OID ASN.1 Value for SPC_RFC3161_OBJID ("1.3.6.1.4.1.311.3.3.1")
|
||||
//
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 mSpcRFC3161OidValue[] = {
|
||||
0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x03, 0x03, 0x01
|
||||
};
|
||||
|
||||
/**
|
||||
Convert ASN.1 GeneralizedTime to EFI Time.
|
||||
|
||||
@param[in] Ptr Pointer to the ASN.1 GeneralizedTime to be converted.
|
||||
@param[out] EfiTime Return the corresponding EFI Time.
|
||||
|
||||
@retval TRUE The time conversion succeeds.
|
||||
@retval FALSE Invalid parameters.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
BOOLEAN
|
||||
ConvertAsn1TimeToEfiTime (
|
||||
IN UINT8 *Ptr,
|
||||
OUT EFI_TIME *EfiTime
|
||||
)
|
||||
{
|
||||
CONST CHAR8 *Str;
|
||||
UINTN Index;
|
||||
|
||||
if ((Ptr == NULL) || (EfiTime == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Str = (CONST CHAR8 *)Ptr;
|
||||
SetMem (EfiTime, sizeof (EFI_TIME), 0);
|
||||
|
||||
Index = 0;
|
||||
|
||||
/* four digit year */
|
||||
EfiTime->Year = (Str[Index++] - '0') * 1000;
|
||||
EfiTime->Year += (Str[Index++] - '0') * 100;
|
||||
EfiTime->Year += (Str[Index++] - '0') * 10;
|
||||
EfiTime->Year += (Str[Index++] - '0');
|
||||
if ((EfiTime->Year < 1900) || (EfiTime->Year > 9999)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EfiTime->Month = (Str[Index++] - '0') * 10;
|
||||
EfiTime->Month += (Str[Index++] - '0');
|
||||
if ((EfiTime->Month < 1) || (EfiTime->Month > 12)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EfiTime->Day = (Str[Index++] - '0') * 10;
|
||||
EfiTime->Day += (Str[Index++] - '0');
|
||||
if ((EfiTime->Day < 1) || (EfiTime->Day > 31)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EfiTime->Hour = (Str[Index++] - '0') * 10;
|
||||
EfiTime->Hour += (Str[Index++] - '0');
|
||||
if (EfiTime->Hour > 23) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EfiTime->Minute = (Str[Index++] - '0') * 10;
|
||||
EfiTime->Minute += (Str[Index++] - '0');
|
||||
if (EfiTime->Minute > 59) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EfiTime->Second = (Str[Index++] - '0') * 10;
|
||||
EfiTime->Second += (Str[Index++] - '0');
|
||||
if (EfiTime->Second > 59) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Note: we did not adjust the time based on time zone information */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
|
||||
signature.
|
||||
|
||||
Return FALSE to indicate this interface is not supported.
|
||||
|
||||
@param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
|
||||
PE/COFF image to be verified.
|
||||
@param[in] DataSize Size of the Authenticode Signature in bytes.
|
||||
@param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
|
||||
is used for TSA certificate chain verification.
|
||||
@param[in] CertSize Size of the trusted certificate in bytes.
|
||||
@param[out] SigningTime Return the time of timestamp generation time if the timestamp
|
||||
signature is valid.
|
||||
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
ImageTimestampVerify (
|
||||
IN CONST UINT8 *AuthData,
|
||||
IN UINTN DataSize,
|
||||
IN CONST UINT8 *TsaCert,
|
||||
IN UINTN CertSize,
|
||||
OUT EFI_TIME *SigningTime
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 *Ptr;
|
||||
UINT8 *End;
|
||||
INT32 Len;
|
||||
UINTN ObjLen;
|
||||
UINT8 *TempPtr;
|
||||
|
||||
//
|
||||
// Initializations
|
||||
//
|
||||
if (SigningTime != NULL) {
|
||||
SetMem (SigningTime, sizeof (EFI_TIME), 0);
|
||||
}
|
||||
|
||||
//
|
||||
// Input Parameters Checking.
|
||||
//
|
||||
if ((AuthData == NULL) || (TsaCert == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((DataSize > INT_MAX) || (CertSize > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr = (UINT8 *)(UINTN)AuthData;
|
||||
Len = (UINT32)DataSize;
|
||||
End = Ptr + Len;
|
||||
|
||||
// ContentInfo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ContentType
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// content
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
End = Ptr + ObjLen;
|
||||
// signedData
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// version
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// digestAlgo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// encapContentInfo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// cert
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
TempPtr = Ptr;
|
||||
// OPTIONAL CRLs
|
||||
if (mbedtls_asn1_get_tag (&TempPtr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) == 0) {
|
||||
Ptr = TempPtr + ObjLen;
|
||||
}
|
||||
|
||||
// signerInfo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// sub parse
|
||||
// signerInfo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
End = Ptr + ObjLen;
|
||||
|
||||
// version
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// sid
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// digestalgo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// OPTIONAL AuthenticatedAttributes
|
||||
TempPtr = Ptr;
|
||||
if (mbedtls_asn1_get_tag (&TempPtr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) == 0) {
|
||||
Ptr = TempPtr + ObjLen;
|
||||
}
|
||||
|
||||
// signaturealgo
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// signature
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OCTET_STRING) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// OPTIONAL UnauthenticatedAttributes
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, 0xA1) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Attribute
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// type
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (CompareMem (Ptr, mSpcRFC3161OidValue, sizeof (mSpcRFC3161OidValue)) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// values
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// values
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// signedData OID
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// [0]
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// integer
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// SET
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// tST OID
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OCTET_STRING) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Integer
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// policy OID
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// sequence
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
// Integer
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ptr += ObjLen;
|
||||
|
||||
// GeneralizedTime
|
||||
if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_GENERALIZED_TIME) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve the signing time from TS_TST_INFO structure.
|
||||
//
|
||||
if (SigningTime != NULL) {
|
||||
SetMem (SigningTime, sizeof (EFI_TIME), 0);
|
||||
Status = ConvertAsn1TimeToEfiTime (Ptr, SigningTime);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
1940
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c
Normal file
1940
CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -377,8 +377,7 @@ EFIAPI
|
||||
X509GetSerialNumber (
|
||||
IN CONST UINT8 *Cert,
|
||||
IN UINTN CertSize,
|
||||
OUT UINT8 *SerialNumber,
|
||||
OPTIONAL
|
||||
OUT UINT8 *SerialNumber OPTIONAL,
|
||||
IN OUT UINTN *SerialNumberSize
|
||||
)
|
||||
{
|
||||
@ -441,8 +440,7 @@ EFIAPI
|
||||
X509GetSignatureAlgorithm (
|
||||
IN CONST UINT8 *Cert,
|
||||
IN UINTN CertSize,
|
||||
OUT UINT8 *Oid,
|
||||
OPTIONAL
|
||||
OUT UINT8 *Oid OPTIONAL,
|
||||
IN OUT UINTN *OidSize
|
||||
)
|
||||
{
|
||||
|
114
CryptoPkg/Library/BaseCryptLibMbedTls/Rand/CryptRand.c
Normal file
114
CryptoPkg/Library/BaseCryptLibMbedTls/Rand/CryptRand.c
Normal file
@ -0,0 +1,114 @@
|
||||
/** @file
|
||||
Pseudorandom Number Generator Wrapper Implementation over MbedTLS.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <Library/RngLib.h>
|
||||
|
||||
/**
|
||||
Sets up the seed value for the pseudorandom number generator.
|
||||
|
||||
This function sets up the seed value for the pseudorandom number generator.
|
||||
If Seed is not NULL, then the seed passed in is used.
|
||||
If Seed is NULL, then default seed is used.
|
||||
|
||||
@param[in] Seed Pointer to seed value.
|
||||
If NULL, default seed is used.
|
||||
@param[in] SeedSize Size of seed value.
|
||||
If Seed is NULL, this parameter is ignored.
|
||||
|
||||
@retval TRUE Pseudorandom number generator has enough entropy for random generation.
|
||||
@retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RandomSeed (
|
||||
IN CONST UINT8 *Seed OPTIONAL,
|
||||
IN UINTN SeedSize
|
||||
)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Generates a pseudorandom byte stream of the specified size.
|
||||
|
||||
If Output is NULL, then return FALSE.
|
||||
|
||||
@param[out] Output Pointer to buffer to receive random value.
|
||||
@param[in] Size Size of random bytes to generate.
|
||||
|
||||
@retval TRUE Pseudorandom byte stream generated successfully.
|
||||
@retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RandomBytes (
|
||||
OUT UINT8 *Output,
|
||||
IN UINTN Size
|
||||
)
|
||||
{
|
||||
BOOLEAN Ret;
|
||||
volatile UINT64 TempRand;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((Output == NULL) || (Size > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = FALSE;
|
||||
|
||||
while (Size > 0) {
|
||||
// Use RngLib to get random number
|
||||
Ret = GetRandomNumber64 ((UINT64 *)&TempRand);
|
||||
|
||||
if (!Ret) {
|
||||
TempRand = 0;
|
||||
return Ret;
|
||||
}
|
||||
|
||||
if (Size >= sizeof (TempRand)) {
|
||||
*((UINT64 *)Output) = TempRand;
|
||||
Output += sizeof (UINT64);
|
||||
Size -= sizeof (TempRand);
|
||||
} else {
|
||||
CopyMem (Output, (VOID *)&TempRand, Size);
|
||||
Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
TempRand = 0;
|
||||
return Ret;
|
||||
}
|
||||
|
||||
/**
|
||||
The MbedTLS function f_rng, which MbedtlsRand implements.
|
||||
|
||||
@param[in] RngState Not used, just for compatibility with mbedlts.
|
||||
@param[out] Output Pointer to buffer to receive random value.
|
||||
@param[in] Len Size of random bytes to generate.
|
||||
|
||||
@retval 0 Pseudorandom byte stream generated successfully.
|
||||
@retval Non-0 Pseudorandom number generator fails to generate due to lack of entropy.
|
||||
**/
|
||||
INT32
|
||||
MbedtlsRand (
|
||||
VOID *RngState,
|
||||
UINT8 *Output,
|
||||
UINTN Len
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
|
||||
Result = RandomBytes (Output, Len);
|
||||
|
||||
return Result ? 0 : -1;
|
||||
}
|
114
CryptoPkg/Library/BaseCryptLibMbedTls/Rand/CryptRandTsc.c
Normal file
114
CryptoPkg/Library/BaseCryptLibMbedTls/Rand/CryptRandTsc.c
Normal file
@ -0,0 +1,114 @@
|
||||
/** @file
|
||||
Pseudorandom Number Generator Wrapper Implementation over MbedTLS.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
#include <Library/RngLib.h>
|
||||
|
||||
/**
|
||||
Sets up the seed value for the pseudorandom number generator.
|
||||
|
||||
This function sets up the seed value for the pseudorandom number generator.
|
||||
If Seed is not NULL, then the seed passed in is used.
|
||||
If Seed is NULL, then default seed is used.
|
||||
|
||||
@param[in] Seed Pointer to seed value.
|
||||
If NULL, default seed is used.
|
||||
@param[in] SeedSize Size of seed value.
|
||||
If Seed is NULL, this parameter is ignored.
|
||||
|
||||
@retval TRUE Pseudorandom number generator has enough entropy for random generation.
|
||||
@retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RandomSeed (
|
||||
IN CONST UINT8 *Seed OPTIONAL,
|
||||
IN UINTN SeedSize
|
||||
)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Generates a pseudorandom byte stream of the specified size.
|
||||
|
||||
If Output is NULL, then return FALSE.
|
||||
|
||||
@param[out] Output Pointer to buffer to receive random value.
|
||||
@param[in] Size Size of random bytes to generate.
|
||||
|
||||
@retval TRUE Pseudorandom byte stream generated successfully.
|
||||
@retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RandomBytes (
|
||||
OUT UINT8 *Output,
|
||||
IN UINTN Size
|
||||
)
|
||||
{
|
||||
BOOLEAN Ret;
|
||||
volatile UINT64 TempRand;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
//
|
||||
if ((Output == NULL) || (Size > INT_MAX)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Ret = FALSE;
|
||||
|
||||
while (Size > 0) {
|
||||
// Use RngLib to get random number
|
||||
Ret = GetRandomNumber64 ((UINT64 *)&TempRand);
|
||||
|
||||
if (!Ret) {
|
||||
TempRand = 0;
|
||||
return Ret;
|
||||
}
|
||||
|
||||
if (Size >= sizeof (TempRand)) {
|
||||
*((UINT64 *)Output) = TempRand;
|
||||
Output += sizeof (UINT64);
|
||||
Size -= sizeof (TempRand);
|
||||
} else {
|
||||
CopyMem (Output, (VOID *)&TempRand, Size);
|
||||
Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
TempRand = 0;
|
||||
return Ret;
|
||||
}
|
||||
|
||||
/**
|
||||
The MbedTLS function f_rng, which MbedtlsRand implements.
|
||||
|
||||
@param[in] RngState Not used, just for compatibility with mbedlts.
|
||||
@param[out] Output Pointer to buffer to receive random value.
|
||||
@param[in] Len Size of random bytes to generate.
|
||||
|
||||
@retval 0 Pseudorandom byte stream generated successfully.
|
||||
@retval Non-0 Pseudorandom number generator fails to generate due to lack of entropy.
|
||||
**/
|
||||
INT32
|
||||
MbedtlsRand (
|
||||
VOID *RngState,
|
||||
UINT8 *Output,
|
||||
UINTN Len
|
||||
)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
|
||||
Result = RandomBytes (Output, Len);
|
||||
|
||||
return Result ? 0 : -1;
|
||||
}
|
@ -37,32 +37,35 @@
|
||||
Hash/CryptMd5.c
|
||||
Hash/CryptSha1.c
|
||||
Hash/CryptSha256.c
|
||||
Hash/CryptSm3Null.c
|
||||
Hash/CryptSha512.c
|
||||
Hash/CryptParallelHashNull.c
|
||||
Hash/CryptSm3.c
|
||||
Hmac/CryptHmac.c
|
||||
Kdf/CryptHkdf.c
|
||||
Cipher/CryptAes.c
|
||||
Cipher/CryptAeadAesGcmNull.c
|
||||
Pk/CryptRsaBasic.c
|
||||
Pk/CryptRsaExtNull.c
|
||||
Pk/CryptRsaPssNull.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Bn/CryptBnNull.c
|
||||
Pem/CryptPemNull.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pk/CryptPkcs1OaepNull.c
|
||||
Pk/CryptPkcs5Pbkdf2Null.c
|
||||
Pk/CryptPkcs7SignNull.c
|
||||
Pk/CryptPkcs7VerifyNull.c
|
||||
Pk/CryptPkcs7VerifyEkuNull.c
|
||||
Pk/CryptX509Null.c
|
||||
Pk/CryptPkcs7VerifyCommon.c
|
||||
Pk/CryptPkcs7VerifyRuntime.c
|
||||
Pk/CryptPkcs7VerifyEkuRuntime.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptX509.c
|
||||
Pk/CryptAuthenticodeNull.c
|
||||
Pk/CryptTsNull.c
|
||||
Rand/CryptRandNull.c
|
||||
Pk/CryptRsaPssNull.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pem/CryptPem.c
|
||||
Bn/CryptBnNull.c
|
||||
Rand/CryptRand.c
|
||||
|
||||
SysCall/CrtWrapper.c
|
||||
SysCall/TimerWrapper.c
|
||||
SysCall/DummyOpensslSupport.c
|
||||
SysCall/RuntimeMemAllocation.c
|
||||
|
||||
[Packages]
|
||||
@ -75,8 +78,10 @@
|
||||
UefiRuntimeServicesTableLib
|
||||
DebugLib
|
||||
MbedTlsLib
|
||||
OpensslLib
|
||||
IntrinsicLib
|
||||
PrintLib
|
||||
RngLib
|
||||
|
||||
#
|
||||
# Remove these [BuildOptions] after this library is cleaned up
|
||||
|
@ -29,7 +29,6 @@
|
||||
[Sources]
|
||||
InternalCryptLib.h
|
||||
Hash/CryptSha512.c
|
||||
|
||||
Hash/CryptMd5Null.c
|
||||
Hash/CryptSha1Null.c
|
||||
Hash/CryptSha256Null.c
|
||||
|
@ -36,31 +36,35 @@
|
||||
Hash/CryptMd5.c
|
||||
Hash/CryptSha1.c
|
||||
Hash/CryptSha256.c
|
||||
Hash/CryptSm3Null.c
|
||||
Hash/CryptSha512.c
|
||||
Hash/CryptParallelHashNull.c
|
||||
Hash/CryptSm3.c
|
||||
Hmac/CryptHmac.c
|
||||
Kdf/CryptHkdf.c
|
||||
Cipher/CryptAes.c
|
||||
Cipher/CryptAeadAesGcmNull.c
|
||||
Pk/CryptRsaBasic.c
|
||||
Pk/CryptRsaExtNull.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Bn/CryptBnNull.c
|
||||
Pem/CryptPemNull.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pk/CryptPkcs1OaepNull.c
|
||||
Pk/CryptPkcs5Pbkdf2Null.c
|
||||
Pk/CryptPkcs1Oaep.c
|
||||
Pk/CryptPkcs5Pbkdf2.c
|
||||
Pk/CryptPkcs7SignNull.c
|
||||
Pk/CryptPkcs7VerifyNull.c
|
||||
Pk/CryptPkcs7VerifyEkuNull.c
|
||||
Pk/CryptX509Null.c
|
||||
Pk/CryptPkcs7VerifyCommon.c
|
||||
Pk/CryptPkcs7VerifyBase.c
|
||||
Pk/CryptPkcs7VerifyEku.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptX509.c
|
||||
Pk/CryptAuthenticodeNull.c
|
||||
Pk/CryptTsNull.c
|
||||
Rand/CryptRandNull.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pem/CryptPem.c
|
||||
Bn/CryptBnNull.c
|
||||
Rand/CryptRand.c
|
||||
|
||||
SysCall/CrtWrapper.c
|
||||
SysCall/DummyOpensslSupport.c
|
||||
SysCall/BaseMemAllocation.c
|
||||
SysCall/ConstantTimeClock.c
|
||||
|
||||
[Packages]
|
||||
@ -72,9 +76,11 @@
|
||||
BaseMemoryLib
|
||||
MemoryAllocationLib
|
||||
MbedTlsLib
|
||||
OpensslLib
|
||||
IntrinsicLib
|
||||
PrintLib
|
||||
MmServicesTableLib
|
||||
RngLib
|
||||
SynchronizationLib
|
||||
|
||||
#
|
||||
|
@ -0,0 +1,122 @@
|
||||
/** @file
|
||||
Base Memory Allocation Routines Wrapper for Crypto library over OpenSSL
|
||||
during PEI & DXE phases.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <CrtLibSupport.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
|
||||
//
|
||||
// Extra header to record the memory buffer size from malloc routine.
|
||||
//
|
||||
#define CRYPTMEM_HEAD_SIGNATURE SIGNATURE_32('c','m','h','d')
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
UINT32 Reserved;
|
||||
UINTN Size;
|
||||
} CRYPTMEM_HEAD;
|
||||
|
||||
#define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
|
||||
|
||||
//
|
||||
// -- Memory-Allocation Routines --
|
||||
//
|
||||
|
||||
/* Allocates memory blocks */
|
||||
void *
|
||||
malloc (
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
CRYPTMEM_HEAD *PoolHdr;
|
||||
UINTN NewSize;
|
||||
VOID *Data;
|
||||
|
||||
//
|
||||
// Adjust the size by the buffer header overhead
|
||||
//
|
||||
NewSize = (UINTN)(size) + CRYPTMEM_OVERHEAD;
|
||||
|
||||
Data = AllocatePool (NewSize);
|
||||
if (Data != NULL) {
|
||||
PoolHdr = (CRYPTMEM_HEAD *)Data;
|
||||
//
|
||||
// Record the memory brief information
|
||||
//
|
||||
PoolHdr->Signature = CRYPTMEM_HEAD_SIGNATURE;
|
||||
PoolHdr->Size = size;
|
||||
|
||||
return (VOID *)(PoolHdr + 1);
|
||||
} else {
|
||||
//
|
||||
// The buffer allocation failed.
|
||||
//
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reallocate memory blocks */
|
||||
void *
|
||||
realloc (
|
||||
void *ptr,
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
CRYPTMEM_HEAD *OldPoolHdr;
|
||||
CRYPTMEM_HEAD *NewPoolHdr;
|
||||
UINTN OldSize;
|
||||
UINTN NewSize;
|
||||
VOID *Data;
|
||||
|
||||
NewSize = (UINTN)size + CRYPTMEM_OVERHEAD;
|
||||
Data = AllocatePool (NewSize);
|
||||
if (Data != NULL) {
|
||||
NewPoolHdr = (CRYPTMEM_HEAD *)Data;
|
||||
NewPoolHdr->Signature = CRYPTMEM_HEAD_SIGNATURE;
|
||||
NewPoolHdr->Size = size;
|
||||
if (ptr != NULL) {
|
||||
//
|
||||
// Retrieve the original size from the buffer header.
|
||||
//
|
||||
OldPoolHdr = (CRYPTMEM_HEAD *)ptr - 1;
|
||||
ASSERT (OldPoolHdr->Signature == CRYPTMEM_HEAD_SIGNATURE);
|
||||
OldSize = OldPoolHdr->Size;
|
||||
|
||||
//
|
||||
// Duplicate the buffer content.
|
||||
//
|
||||
CopyMem ((VOID *)(NewPoolHdr + 1), ptr, MIN (OldSize, size));
|
||||
FreePool ((VOID *)OldPoolHdr);
|
||||
}
|
||||
|
||||
return (VOID *)(NewPoolHdr + 1);
|
||||
} else {
|
||||
//
|
||||
// The buffer allocation failed.
|
||||
//
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* De-allocates or frees a memory block */
|
||||
void
|
||||
free (
|
||||
void *ptr
|
||||
)
|
||||
{
|
||||
CRYPTMEM_HEAD *PoolHdr;
|
||||
|
||||
//
|
||||
// In Standard C, free() handles a null pointer argument transparently. This
|
||||
// is not true of FreePool() below, so protect it.
|
||||
//
|
||||
if (ptr != NULL) {
|
||||
PoolHdr = (CRYPTMEM_HEAD *)ptr - 1;
|
||||
ASSERT (PoolHdr->Signature == CRYPTMEM_HEAD_SIGNATURE);
|
||||
FreePool (PoolHdr);
|
||||
}
|
||||
}
|
@ -0,0 +1,571 @@
|
||||
/**
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
#include <CrtLibSupport.h>
|
||||
|
||||
int errno = 0;
|
||||
|
||||
FILE *stderr = NULL;
|
||||
FILE *stdin = NULL;
|
||||
FILE *stdout = NULL;
|
||||
|
||||
typedef
|
||||
int
|
||||
(*SORT_COMPARE)(
|
||||
IN VOID *Buffer1,
|
||||
IN VOID *Buffer2
|
||||
);
|
||||
|
||||
//
|
||||
// Duplicated from EDKII BaseSortLib for qsort() wrapper
|
||||
//
|
||||
STATIC
|
||||
VOID
|
||||
QuickSortWorker (
|
||||
IN OUT VOID *BufferToSort,
|
||||
IN CONST UINTN Count,
|
||||
IN CONST UINTN ElementSize,
|
||||
IN SORT_COMPARE CompareFunction,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
VOID *Pivot;
|
||||
UINTN LoopCount;
|
||||
UINTN NextSwapLocation;
|
||||
|
||||
ASSERT (BufferToSort != NULL);
|
||||
ASSERT (CompareFunction != NULL);
|
||||
ASSERT (Buffer != NULL);
|
||||
|
||||
if ((Count < 2) || (ElementSize < 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NextSwapLocation = 0;
|
||||
|
||||
//
|
||||
// Pick a pivot (we choose last element)
|
||||
//
|
||||
Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));
|
||||
|
||||
//
|
||||
// Now get the pivot such that all on "left" are below it
|
||||
// and everything "right" are above it
|
||||
//
|
||||
for (LoopCount = 0; LoopCount < Count - 1; LoopCount++) {
|
||||
//
|
||||
// If the element is less than the pivot
|
||||
//
|
||||
if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {
|
||||
//
|
||||
// Swap
|
||||
//
|
||||
CopyMem (Buffer, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
|
||||
CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), (UINT8 *)BufferToSort + ((LoopCount) * ElementSize), ElementSize);
|
||||
CopyMem ((UINT8 *)BufferToSort + ((LoopCount) * ElementSize), Buffer, ElementSize);
|
||||
|
||||
//
|
||||
// Increment NextSwapLocation
|
||||
//
|
||||
NextSwapLocation++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Swap pivot to its final position (NextSwapLocation)
|
||||
//
|
||||
CopyMem (Buffer, Pivot, ElementSize);
|
||||
CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
|
||||
CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);
|
||||
|
||||
//
|
||||
// Now recurse on 2 partial lists. Neither of these will have the 'pivot' element.
|
||||
// IE list is sorted left half, pivot element, sorted right half...
|
||||
//
|
||||
QuickSortWorker (
|
||||
BufferToSort,
|
||||
NextSwapLocation,
|
||||
ElementSize,
|
||||
CompareFunction,
|
||||
Buffer
|
||||
);
|
||||
|
||||
QuickSortWorker (
|
||||
(UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,
|
||||
Count - NextSwapLocation - 1,
|
||||
ElementSize,
|
||||
CompareFunction,
|
||||
Buffer
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Standard C Run-time Library Interface Wrapper
|
||||
// ---------------------------------------------------------
|
||||
|
||||
//
|
||||
// -- String Manipulation Routines --
|
||||
//
|
||||
|
||||
/* Scan a string for the last occurrence of a character */
|
||||
char *
|
||||
strrchr (
|
||||
const char *str,
|
||||
int c
|
||||
)
|
||||
{
|
||||
char *save;
|
||||
|
||||
for (save = NULL; ; ++str) {
|
||||
if (*str == c) {
|
||||
save = (char *)str;
|
||||
}
|
||||
|
||||
if (*str == 0) {
|
||||
return (save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compare first n bytes of string s1 with string s2, ignoring case */
|
||||
int
|
||||
strncasecmp (
|
||||
const char *s1,
|
||||
const char *s2,
|
||||
size_t n
|
||||
)
|
||||
{
|
||||
int Val;
|
||||
|
||||
ASSERT (s1 != NULL);
|
||||
ASSERT (s2 != NULL);
|
||||
|
||||
if (n != 0) {
|
||||
do {
|
||||
Val = tolower (*s1) - tolower (*s2);
|
||||
if (Val != 0) {
|
||||
return Val;
|
||||
}
|
||||
|
||||
++s1;
|
||||
++s2;
|
||||
if (*s1 == '\0') {
|
||||
break;
|
||||
}
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read formatted data from a string */
|
||||
int
|
||||
sscanf (
|
||||
const char *buffer,
|
||||
const char *format,
|
||||
...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Null sscanf() function implementation to satisfy the linker, since
|
||||
// no direct functionality logic dependency in present UEFI cases.
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Maps errnum to an error-message string */
|
||||
char *
|
||||
strerror (
|
||||
int errnum
|
||||
)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Computes the length of the maximum initial segment of the string pointed to by s1
|
||||
which consists entirely of characters from the string pointed to by s2. */
|
||||
size_t
|
||||
strspn (
|
||||
const char *s1,
|
||||
const char *s2
|
||||
)
|
||||
{
|
||||
UINT8 Map[32];
|
||||
UINT32 Index;
|
||||
size_t Count;
|
||||
|
||||
for (Index = 0; Index < 32; Index++) {
|
||||
Map[Index] = 0;
|
||||
}
|
||||
|
||||
while (*s2) {
|
||||
Map[*s2 >> 3] |= (1 << (*s2 & 7));
|
||||
s2++;
|
||||
}
|
||||
|
||||
if (*s1) {
|
||||
Count = 0;
|
||||
while (Map[*s1 >> 3] & (1 << (*s1 & 7))) {
|
||||
Count++;
|
||||
s1++;
|
||||
}
|
||||
|
||||
return Count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Computes the length of the maximum initial segment of the string pointed to by s1
|
||||
which consists entirely of characters not from the string pointed to by s2. */
|
||||
size_t
|
||||
strcspn (
|
||||
const char *s1,
|
||||
const char *s2
|
||||
)
|
||||
{
|
||||
UINT8 Map[32];
|
||||
UINT32 Index;
|
||||
size_t Count;
|
||||
|
||||
for (Index = 0; Index < 32; Index++) {
|
||||
Map[Index] = 0;
|
||||
}
|
||||
|
||||
while (*s2) {
|
||||
Map[*s2 >> 3] |= (1 << (*s2 & 7));
|
||||
s2++;
|
||||
}
|
||||
|
||||
Map[0] |= 1;
|
||||
|
||||
Count = 0;
|
||||
while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) {
|
||||
Count++;
|
||||
s1++;
|
||||
}
|
||||
|
||||
return Count;
|
||||
}
|
||||
|
||||
char *
|
||||
strcpy (
|
||||
char *strDest,
|
||||
const char *strSource
|
||||
)
|
||||
{
|
||||
// AsciiStrCpyS (strDest, MAX_STRING_SIZE, strSource);
|
||||
// return strDest;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// -- Character Classification Routines --
|
||||
//
|
||||
|
||||
/* Determines if a particular character is a decimal-digit character */
|
||||
int
|
||||
isdigit (
|
||||
int c
|
||||
)
|
||||
{
|
||||
//
|
||||
// <digit> ::= [0-9]
|
||||
//
|
||||
return (('0' <= (c)) && ((c) <= '9'));
|
||||
}
|
||||
|
||||
/* Determine if an integer represents character that is a hex digit */
|
||||
int
|
||||
isxdigit (
|
||||
int c
|
||||
)
|
||||
{
|
||||
//
|
||||
// <hexdigit> ::= [0-9] | [a-f] | [A-F]
|
||||
//
|
||||
return ((('0' <= (c)) && ((c) <= '9')) ||
|
||||
(('a' <= (c)) && ((c) <= 'f')) ||
|
||||
(('A' <= (c)) && ((c) <= 'F')));
|
||||
}
|
||||
|
||||
/* Determines if a particular character represents a space character */
|
||||
int
|
||||
isspace (
|
||||
int c
|
||||
)
|
||||
{
|
||||
//
|
||||
// <space> ::= [ ]
|
||||
//
|
||||
return ((c) == ' ');
|
||||
}
|
||||
|
||||
/* Determine if a particular character is an alphanumeric character */
|
||||
int
|
||||
isalnum (
|
||||
int c
|
||||
)
|
||||
{
|
||||
//
|
||||
// <alnum> ::= [0-9] | [a-z] | [A-Z]
|
||||
//
|
||||
return ((('0' <= (c)) && ((c) <= '9')) ||
|
||||
(('a' <= (c)) && ((c) <= 'z')) ||
|
||||
(('A' <= (c)) && ((c) <= 'Z')));
|
||||
}
|
||||
|
||||
/* Determines if a particular character is in upper case */
|
||||
int
|
||||
isupper (
|
||||
int c
|
||||
)
|
||||
{
|
||||
//
|
||||
// <uppercase letter> := [A-Z]
|
||||
//
|
||||
return (('A' <= (c)) && ((c) <= 'Z'));
|
||||
}
|
||||
|
||||
//
|
||||
// -- Data Conversion Routines --
|
||||
//
|
||||
|
||||
/* Convert strings to a long-integer value */
|
||||
long
|
||||
strtol (
|
||||
const char *nptr,
|
||||
char **endptr,
|
||||
int base
|
||||
)
|
||||
{
|
||||
//
|
||||
// Null strtol() function implementation to satisfy the linker, since there is
|
||||
// no direct functionality logic dependency in present UEFI cases.
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert strings to an unsigned long-integer value */
|
||||
unsigned long
|
||||
strtoul (
|
||||
const char *nptr,
|
||||
char **endptr,
|
||||
int base
|
||||
)
|
||||
{
|
||||
//
|
||||
// Null strtoul() function implementation to satisfy the linker, since there is
|
||||
// no direct functionality logic dependency in present UEFI cases.
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert character to lowercase */
|
||||
int
|
||||
tolower (
|
||||
int c
|
||||
)
|
||||
{
|
||||
if (('A' <= (c)) && ((c) <= 'Z')) {
|
||||
return (c - ('A' - 'a'));
|
||||
}
|
||||
|
||||
return (c);
|
||||
}
|
||||
|
||||
//
|
||||
// -- Searching and Sorting Routines --
|
||||
//
|
||||
|
||||
/* Performs a quick sort */
|
||||
void
|
||||
qsort (
|
||||
void *base,
|
||||
size_t num,
|
||||
size_t width,
|
||||
int ( *compare )(const void *, const void *)
|
||||
)
|
||||
{
|
||||
VOID *Buffer;
|
||||
|
||||
ASSERT (base != NULL);
|
||||
ASSERT (compare != NULL);
|
||||
|
||||
//
|
||||
// Use CRT-style malloc to cover BS and RT memory allocation.
|
||||
//
|
||||
Buffer = malloc (width);
|
||||
ASSERT (Buffer != NULL);
|
||||
|
||||
//
|
||||
// Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
|
||||
//
|
||||
QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);
|
||||
|
||||
free (Buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// -- Process and Environment Control Routines --
|
||||
//
|
||||
|
||||
/* Get a value from the current environment */
|
||||
char *
|
||||
getenv (
|
||||
const char *varname
|
||||
)
|
||||
{
|
||||
//
|
||||
// Null getenv() function implementation to satisfy the linker, since there is
|
||||
// no direct functionality logic dependency in present UEFI cases.
|
||||
//
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get a value from the current environment */
|
||||
char *
|
||||
secure_getenv (
|
||||
const char *varname
|
||||
)
|
||||
{
|
||||
//
|
||||
// Null secure_getenv() function implementation to satisfy the linker, since
|
||||
// there is no direct functionality logic dependency in present UEFI cases.
|
||||
//
|
||||
// From the secure_getenv() manual: 'just like getenv() except that it
|
||||
// returns NULL in cases where "secure execution" is required'.
|
||||
//
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// -- Stream I/O Routines --
|
||||
//
|
||||
|
||||
/* Write data to a stream */
|
||||
size_t
|
||||
fwrite (
|
||||
const void *buffer,
|
||||
size_t size,
|
||||
size_t count,
|
||||
FILE *stream
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *NoReturnFuncPtr)(
|
||||
VOID
|
||||
) __attribute__ ((__noreturn__));
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
NopFunction (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
abort (
|
||||
void
|
||||
)
|
||||
{
|
||||
NoReturnFuncPtr NoReturnFunc;
|
||||
|
||||
NoReturnFunc = (NoReturnFuncPtr)NopFunction;
|
||||
|
||||
NoReturnFunc ();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
abort (
|
||||
void
|
||||
)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
fclose (
|
||||
FILE *f
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *
|
||||
fopen (
|
||||
const char *c,
|
||||
const char *m
|
||||
)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
fread (
|
||||
void *b,
|
||||
size_t c,
|
||||
size_t i,
|
||||
FILE *f
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uid_t
|
||||
getuid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uid_t
|
||||
geteuid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t
|
||||
getgid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t
|
||||
getegid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
printf (
|
||||
char const *fmt,
|
||||
...
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/** @file
|
||||
C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based
|
||||
Cryptographic Library.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) Microsoft Corporation
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Base.h>
|
||||
#include <Library/DebugLib.h>
|
||||
|
||||
/* Read formatted data from a string */
|
||||
int
|
||||
sscanf (
|
||||
const char *buffer,
|
||||
const char *format,
|
||||
...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Null sscanf() function implementation to satisfy the linker, since
|
||||
// no direct functionality logic dependency in present UEFI cases.
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
uid_t
|
||||
getuid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uid_t
|
||||
geteuid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t
|
||||
getgid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t
|
||||
getegid (
|
||||
void
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int errno = 0;
|
@ -27,33 +27,36 @@
|
||||
|
||||
[Sources]
|
||||
InternalCryptLib.h
|
||||
Cipher/CryptAeadAesGcmNull.c
|
||||
Cipher/CryptAes.c
|
||||
Hash/CryptSha256.c
|
||||
Hash/CryptSha512.c
|
||||
Hash/CryptSm3Null.c
|
||||
Hash/CryptMd5.c
|
||||
Hash/CryptSha1.c
|
||||
Hash/CryptSha256.c
|
||||
Hash/CryptSha512.c
|
||||
Hash/CryptSm3.c
|
||||
Hash/CryptParallelHashNull.c
|
||||
Hmac/CryptHmac.c
|
||||
Kdf/CryptHkdf.c
|
||||
Cipher/CryptAes.c
|
||||
Cipher/CryptAeadAesGcm.c
|
||||
Pk/CryptRsaBasic.c
|
||||
Pk/CryptRsaExtNull.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSignNull.c
|
||||
Bn/CryptBnNull.c
|
||||
Pem/CryptPemNull.c
|
||||
Pk/CryptRsaExt.c
|
||||
Pk/CryptPkcs1Oaep.c
|
||||
Pk/CryptPkcs5Pbkdf2.c
|
||||
Pk/CryptPkcs7Sign.c
|
||||
Pk/CryptPkcs7VerifyCommon.c
|
||||
Pk/CryptPkcs7VerifyBase.c
|
||||
Pk/CryptPkcs7VerifyEku.c
|
||||
Pk/CryptDhNull.c
|
||||
Pk/CryptX509.c
|
||||
Pk/CryptAuthenticode.c
|
||||
Pk/CryptTs.c
|
||||
Pem/CryptPem.c
|
||||
Pk/CryptRsaPss.c
|
||||
Pk/CryptRsaPssSign.c
|
||||
Bn/CryptBnNull.c
|
||||
Pk/CryptEcNull.c
|
||||
Pk/CryptPkcs1OaepNull.c
|
||||
Pk/CryptPkcs5Pbkdf2Null.c
|
||||
Pk/CryptPkcs7SignNull.c
|
||||
Pk/CryptPkcs7VerifyNull.c
|
||||
Pk/CryptPkcs7VerifyEkuNull.c
|
||||
Pk/CryptX509Null.c
|
||||
Pk/CryptAuthenticodeNull.c
|
||||
Pk/CryptTsNull.c
|
||||
Rand/CryptRandNull.c
|
||||
Rand/CryptRand.c
|
||||
SysCall/CrtWrapper.c
|
||||
SysCall/UnitTestHostCrtWrapper.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
@ -66,6 +69,7 @@
|
||||
UefiRuntimeServicesTableLib
|
||||
DebugLib
|
||||
MbedTlsLib
|
||||
OpensslLib
|
||||
PrintLib
|
||||
RngLib
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
Copyright (C) 2016 Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (C) Microsoft Corporation. All Rights Reserved.
|
||||
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
||||
|
||||
**/
|
||||
@ -48,3 +48,131 @@ Pkcs1v2Encrypt (
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
ASSERT (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -2825,6 +2825,119 @@ Pkcs1v2Encrypt (
|
||||
CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Pkcs1v2Decrypt (
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
CALL_CRYPTO_SERVICE (Pkcs1v2Decrypt, (PrivateKey, PrivateKeySize, EncryptedData, EncryptedDataSize, OutData, OutDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepEncrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
)
|
||||
{
|
||||
CALL_CRYPTO_SERVICE (RsaOaepEncrypt, (RsaContext, InData, InDataSize, PrngSeed, PrngSeedSize, DigestLen, EncryptedData, EncryptedDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
RsaOaepDecrypt (
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
)
|
||||
{
|
||||
CALL_CRYPTO_SERVICE (RsaOaepDecrypt, (RsaContext, EncryptedData, EncryptedDataSize, DigestLen, OutData, OutDataSize), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
|
||||
Cryptographic Message Syntax Standard". The input signed data could be wrapped
|
||||
@ -2850,6 +2963,7 @@ Pkcs1v2Encrypt (
|
||||
@retval FALSE Error occurs during the operation.
|
||||
@retval FALSE This interface is not supported.
|
||||
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
|
@ -141,6 +141,17 @@ static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
|
||||
ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions),
|
||||
ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions),
|
||||
|
||||
ALGC (
|
||||
PROV_NAMES_AES_128_CBC_HMAC_SHA256,
|
||||
ossl_aes128cbc_hmac_sha256_functions,
|
||||
ossl_cipher_capable_aes_cbc_hmac_sha256
|
||||
),
|
||||
ALGC (
|
||||
PROV_NAMES_AES_256_CBC_HMAC_SHA256,
|
||||
ossl_aes256cbc_hmac_sha256_functions,
|
||||
ossl_cipher_capable_aes_cbc_hmac_sha256
|
||||
),
|
||||
|
||||
{ { NULL, NULL, NULL }, NULL }
|
||||
};
|
||||
static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
|
||||
|
@ -21,7 +21,7 @@
|
||||
/// the EDK II Crypto Protocol is extended, this version define must be
|
||||
/// increased.
|
||||
///
|
||||
#define EDKII_CRYPTO_VERSION 16
|
||||
#define EDKII_CRYPTO_VERSION 17
|
||||
|
||||
///
|
||||
/// EDK II Crypto Protocol forward declaration
|
||||
@ -688,6 +688,110 @@ BOOLEAN
|
||||
OUT UINTN *EncryptedDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
@param[in] PrivateKey A pointer to the DER-encoded private key.
|
||||
@param[in] PrivateKeySize Size of the private key buffer.
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
**/
|
||||
typedef
|
||||
BOOLEAN
|
||||
(EFIAPI *EDKII_CRYPTO_PKCS1V2_DECRYPT)(
|
||||
IN CONST UINT8 *PrivateKey,
|
||||
IN UINTN PrivateKeySize,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
encrypted message in a newly allocated buffer.
|
||||
Things that can cause a failure include:
|
||||
- X509 key size does not match any known key size.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
- Data size is too large for the provided key size (max size is a function of key size
|
||||
and hash digest size).
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a public key using RsaSetKey().
|
||||
@param[in] InData Data to be encrypted.
|
||||
@param[in] InDataSize Size of the data buffer.
|
||||
@param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
|
||||
to be used when initializing the PRNG. NULL otherwise.
|
||||
@param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
|
||||
0 otherwise.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] EncryptedDataSize Size of the encrypted message buffer.
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
**/
|
||||
typedef
|
||||
BOOLEAN
|
||||
(EFIAPI *EDKII_CRYPTO_RSA_OAEP_ENCRYPT)(
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *InData,
|
||||
IN UINTN InDataSize,
|
||||
IN CONST UINT8 *PrngSeed OPTIONAL,
|
||||
IN UINTN PrngSeedSize OPTIONAL,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **EncryptedData,
|
||||
OUT UINTN *EncryptedDataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Decrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
|
||||
decrypted message in a newly allocated buffer.
|
||||
Things that can cause a failure include:
|
||||
- Fail to parse private key.
|
||||
- Fail to allocate an intermediate buffer.
|
||||
- Null pointer provided for a non-optional parameter.
|
||||
@param[in] RsaContext A pointer to an RSA context created by RsaNew() and
|
||||
provisioned with a private key using RsaSetKey().
|
||||
@param[in] EncryptedData Data to be decrypted.
|
||||
@param[in] EncryptedDataSize Size of the encrypted buffer.
|
||||
@param[in] DigestLen [Optional] If provided, size of the hash used:
|
||||
SHA1_DIGEST_SIZE
|
||||
SHA256_DIGEST_SIZE
|
||||
SHA384_DIGEST_SIZE
|
||||
SHA512_DIGEST_SIZE
|
||||
0 to use default (SHA1)
|
||||
@param[out] OutData Pointer to an allocated buffer containing the encrypted
|
||||
message.
|
||||
@param[out] OutDataSize Size of the encrypted message buffer.
|
||||
@retval TRUE Encryption was successful.
|
||||
@retval FALSE Encryption failed.
|
||||
**/
|
||||
typedef
|
||||
BOOLEAN
|
||||
(EFIAPI *EDKII_CRYPTO_RSA_OAEP_DECRYPT)(
|
||||
IN VOID *RsaContext,
|
||||
IN UINT8 *EncryptedData,
|
||||
IN UINTN EncryptedDataSize,
|
||||
IN UINT16 DigestLen OPTIONAL,
|
||||
OUT UINT8 **OutData,
|
||||
OUT UINTN *OutDataSize
|
||||
);
|
||||
|
||||
// ---------------------------------------------
|
||||
// PKCS5
|
||||
|
||||
@ -5603,6 +5707,9 @@ struct _EDKII_CRYPTO_PROTOCOL {
|
||||
EDKII_CRYPTO_X509_GET_CERT_FROM_CERT_CHAIN X509GetCertFromCertChain;
|
||||
EDKII_CRYPTO_ASN1_GET_TAG Asn1GetTag;
|
||||
EDKII_CRYPTO_X509_GET_EXTENDED_BASIC_CONSTRAINTS X509GetExtendedBasicConstraints;
|
||||
EDKII_CRYPTO_PKCS1V2_DECRYPT Pkcs1v2Decrypt;
|
||||
EDKII_CRYPTO_RSA_OAEP_ENCRYPT RsaOaepEncrypt;
|
||||
EDKII_CRYPTO_RSA_OAEP_DECRYPT RsaOaepDecrypt;
|
||||
};
|
||||
|
||||
extern GUID gEdkiiCryptoProtocolGuid;
|
||||
|
@ -1,20 +1,21 @@
|
||||
/** @file
|
||||
This is a unit test for RSA OAEP encrypt.
|
||||
This is a unit test for RSA OAEP encrypt/decrypt.
|
||||
|
||||
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
#include "TestBaseCryptLib.h"
|
||||
|
||||
CONST UINT8 RandSeed[] = "This is the random seed for PRNG verification.";
|
||||
STATIC CONST UINT8 RandSeed[] = "This is the random seed for PRNG verification.";
|
||||
|
||||
//
|
||||
// Self signed X509 certificate
|
||||
// CN = ca.self
|
||||
// O = Intel
|
||||
//
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 SelfTestCert[] = {
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 SelfTestCert[] = {
|
||||
0x30, 0x82, 0x03, 0x90, 0x30, 0x82, 0x02, 0x78, 0x02, 0x09, 0x00, 0xE4, 0xDF, 0x47, 0x80, 0xEF,
|
||||
0x4B, 0x3C, 0x6D, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
|
||||
0x05, 0x00, 0x30, 0x81, 0x89, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
|
||||
@ -75,7 +76,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 SelfTestCert[] = {
|
||||
0x5B, 0x64, 0x81, 0x13,
|
||||
};
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 PrivateKey[] = {
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 PrivateKey[] = {
|
||||
0x30, 0x82, 0x04, 0xA4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xBC, 0xE4, 0x67, 0xDC,
|
||||
0xC7, 0xEA, 0x6F, 0x8A, 0xA7, 0xCC, 0xB2, 0x54, 0x47, 0x48, 0x6A, 0xE2, 0x39, 0xFF, 0xC2, 0x48,
|
||||
0x58, 0x34, 0x07, 0x03, 0x6D, 0x39, 0xB3, 0x67, 0x46, 0x4C, 0xBC, 0xA0, 0xFA, 0x4E, 0x64, 0x23,
|
||||
@ -153,114 +154,442 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 PrivateKey[] = {
|
||||
0x86, 0x10, 0x09, 0x88, 0x6C, 0x35, 0x60, 0xF2,
|
||||
};
|
||||
|
||||
// The following RSA key componets were extracted from the above private key with openssl.
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 RsaN[] = {
|
||||
0x00,
|
||||
0xbc,0xe4, 0x67, 0xdc, 0xc7, 0xea, 0x6f, 0x8a, 0xa7, 0xcc, 0xb2, 0x54, 0x47, 0x48, 0x6a, 0xe2,
|
||||
0x39,0xff, 0xc2, 0x48, 0x58, 0x34, 0x07, 0x03, 0x6d, 0x39, 0xb3, 0x67, 0x46, 0x4c, 0xbc, 0xa0,
|
||||
0xfa,0x4e, 0x64, 0x23, 0x56, 0x47, 0x7b, 0xc9, 0x1a, 0x2a, 0x55, 0x42, 0x54, 0x10, 0x18, 0x30,
|
||||
0x92,0x60, 0x30, 0x5b, 0x9e, 0xc0, 0x65, 0xd2, 0xd4, 0x05, 0x4a, 0xa6, 0x10, 0x66, 0x04, 0xa9,
|
||||
0x54,0x4e, 0xee, 0x49, 0x39, 0x43, 0x65, 0x1e, 0x2e, 0x28, 0xde, 0x79, 0x24, 0xa9, 0x7e, 0xd8,
|
||||
0x5b,0xbc, 0x2f, 0x46, 0x6a, 0xb7, 0xb6, 0x0d, 0x17, 0x88, 0x37, 0x52, 0x5c, 0xfe, 0x93, 0xc0,
|
||||
0xe2,0xfd, 0x6a, 0x08, 0x1b, 0xfb, 0xd1, 0x87, 0xbd, 0xbd, 0x58, 0x57, 0x2c, 0x06, 0x5d, 0xd2,
|
||||
0x7d,0x52, 0xe2, 0x49, 0x8e, 0xdc, 0xe5, 0x26, 0xbd, 0x92, 0x60, 0xb0, 0x3f, 0x58, 0x5e, 0x52,
|
||||
0xd7,0x91, 0xda, 0x93, 0x62, 0x8d, 0x71, 0x80, 0x53, 0xba, 0x15, 0xc4, 0x1f, 0xf3, 0xbd, 0xe0,
|
||||
0xc5,0xa4, 0xb8, 0xd3, 0x64, 0x12, 0x14, 0x1b, 0x11, 0x6b, 0x7b, 0xc2, 0x92, 0xc7, 0xe2, 0x94,
|
||||
0x0b,0xb8, 0x67, 0x38, 0x48, 0x63, 0x11, 0x74, 0x25, 0x7c, 0x37, 0xc3, 0xb2, 0xae, 0xd9, 0xa7,
|
||||
0x17,0x9c, 0x4b, 0x9d, 0x6c, 0x27, 0xb0, 0x87, 0x16, 0x6b, 0xf2, 0x96, 0xe5, 0x1d, 0x37, 0x27,
|
||||
0xde,0xf2, 0x98, 0xb7, 0x81, 0x08, 0xd9, 0x7a, 0xba, 0x84, 0x14, 0x61, 0x60, 0x48, 0xce, 0xce,
|
||||
0x51,0x73, 0xf4, 0xdb, 0xf1, 0x5f, 0x7a, 0x17, 0x71, 0x4f, 0xc1, 0x0b, 0xce, 0xc7, 0x31, 0xc1,
|
||||
0x4e,0xa3, 0xee, 0x6f, 0x72, 0x97, 0x90, 0xfb, 0x8b, 0x54, 0x9f, 0x82, 0x5b, 0x48, 0x5a, 0xf1,
|
||||
0xad,0x8b, 0x3a, 0xcd, 0xca, 0xb2, 0x8b, 0x7a, 0x53, 0xd4, 0xf7, 0x71, 0x16, 0x75, 0xa7, 0x35,
|
||||
};
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 RsaE[] = {
|
||||
0x01, 0x00, 0x01
|
||||
};
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 RsaD[] = {
|
||||
0x13, 0xf7, 0xd1, 0x42, 0xf5, 0x9f, 0x42, 0xcb, 0x55, 0x91, 0xbe, 0x08, 0x4a, 0xc0, 0xcd, 0x0b,
|
||||
0xbd, 0x35, 0xdc, 0x43, 0xe9, 0x8f, 0x16, 0x6e, 0xb6, 0x4d, 0x33, 0x39, 0xe7, 0xa4, 0x95, 0x0c,
|
||||
0x2f, 0x69, 0xba, 0x0c, 0x42, 0x42, 0xac, 0x43, 0x46, 0x10, 0xd3, 0x92, 0x7f, 0x70, 0x74, 0x1e,
|
||||
0x2e, 0x5b, 0x1c, 0xc1, 0x92, 0xb6, 0xa4, 0x0c, 0xf5, 0x7c, 0xd9, 0xb7, 0x54, 0x64, 0x74, 0x79,
|
||||
0xb1, 0xff, 0xe6, 0x10, 0xb7, 0x8c, 0xf8, 0x53, 0x88, 0x6d, 0xa9, 0x97, 0x04, 0xd9, 0x26, 0x1f,
|
||||
0x99, 0x12, 0xfb, 0xac, 0x65, 0xfb, 0xa5, 0xb3, 0x1c, 0x99, 0xb9, 0xbf, 0x6b, 0x35, 0x3e, 0x49,
|
||||
0x55, 0xb5, 0x94, 0x4f, 0xe7, 0x25, 0x67, 0xb1, 0x01, 0xcd, 0xd2, 0x58, 0xe4, 0xbe, 0x87, 0x8c,
|
||||
0x88, 0xd3, 0x0a, 0x38, 0xdc, 0x71, 0x5d, 0x88, 0x0a, 0xe2, 0x3e, 0x76, 0x63, 0x3b, 0xe4, 0x3c,
|
||||
0x8f, 0x2f, 0x29, 0x1d, 0xd1, 0x66, 0x8d, 0xc0, 0x4a, 0x68, 0x15, 0x90, 0x4c, 0x95, 0x61, 0xf4,
|
||||
0xfd, 0xe8, 0xfa, 0x9c, 0x6c, 0x00, 0x22, 0x23, 0xd5, 0x17, 0x6e, 0xee, 0xa8, 0xd8, 0x70, 0xc5,
|
||||
0x74, 0xea, 0x09, 0x13, 0x7f, 0x0c, 0x37, 0x4d, 0x50, 0xcd, 0xe9, 0x16, 0xc2, 0xd5, 0xde, 0x5e,
|
||||
0xc3, 0xfc, 0x46, 0x08, 0xf1, 0x99, 0xc0, 0xb4, 0x28, 0xfd, 0x2b, 0x29, 0xef, 0x76, 0xd7, 0x04,
|
||||
0x4f, 0x02, 0x54, 0x16, 0x54, 0x55, 0x20, 0xec, 0xbc, 0xbf, 0x85, 0x5f, 0x12, 0xcc, 0xfc, 0x0d,
|
||||
0xf2, 0xef, 0xfc, 0x4d, 0x3e, 0xa2, 0x5e, 0x97, 0xfe, 0x35, 0x10, 0x0f, 0x53, 0x1f, 0x80, 0xd5,
|
||||
0xc0, 0xb4, 0xe9, 0xe9, 0x31, 0x4c, 0x89, 0x14, 0x72, 0x39, 0x65, 0x89, 0xef, 0x7a, 0x51, 0x4a,
|
||||
0xb9, 0xa9, 0xcc, 0x1b, 0x52, 0xb0, 0x02, 0x52, 0x65, 0x2f, 0x0b, 0x89, 0x41, 0x70, 0x1e, 0x01,
|
||||
};
|
||||
|
||||
// test case = "123\0"
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 Msg1230[] = {
|
||||
0x31, 0x32, 0x33, 0x00
|
||||
};
|
||||
|
||||
// Ciphertext of the test case using RSAES-OAEP2048 with SHA1 MD/BGF1 created with openssl.
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 Ct1230RsaesOaepMdSha1Mgf1Sha1[] = {
|
||||
0x88, 0x5d, 0xf3, 0x00, 0x66, 0x77, 0x91, 0x94, 0x5c, 0x8d, 0x45, 0xb6, 0xb2, 0x24, 0x26, 0x26,
|
||||
0x37, 0xbe, 0xe0, 0x87, 0x4f, 0x50, 0xbf, 0x88, 0xde, 0x5d, 0xe9, 0xe0, 0xb2, 0x7e, 0x66, 0xfa,
|
||||
0x6c, 0xfd, 0x0d, 0x19, 0x48, 0x41, 0xfe, 0x7a, 0x86, 0xa8, 0x28, 0xc2, 0x01, 0xcf, 0x76, 0xd7,
|
||||
0xea, 0xab, 0x6d, 0xc3, 0x5e, 0x2c, 0x36, 0x04, 0xc0, 0x54, 0xc2, 0x68, 0x67, 0xe7, 0x04, 0x27,
|
||||
0x56, 0xbe, 0x53, 0xb5, 0x80, 0x94, 0xd8, 0xde, 0x8c, 0x75, 0x69, 0x42, 0xba, 0x55, 0xd6, 0x2c,
|
||||
0xda, 0x22, 0xe6, 0x09, 0xf6, 0x90, 0x27, 0x4b, 0x10, 0x54, 0x40, 0xa0, 0x74, 0x31, 0xdb, 0x5f,
|
||||
0x80, 0x06, 0xc7, 0x67, 0x96, 0xe8, 0x45, 0xea, 0x7f, 0x72, 0x18, 0x24, 0xe8, 0x0d, 0x46, 0xc2,
|
||||
0xa0, 0x83, 0xca, 0x71, 0xca, 0x91, 0x4b, 0x89, 0x80, 0x61, 0x01, 0x8e, 0xcf, 0xa1, 0x68, 0x81,
|
||||
0x2d, 0xf2, 0x08, 0xd2, 0x02, 0x9e, 0xc0, 0xa4, 0x91, 0x71, 0x90, 0x84, 0x2f, 0x4e, 0x18, 0x37,
|
||||
0x9b, 0x61, 0x0b, 0xf5, 0x88, 0xf7, 0x6b, 0x87, 0xb9, 0x4e, 0x31, 0xda, 0xf3, 0xb5, 0xe2, 0x60,
|
||||
0x4d, 0xd9, 0x52, 0x99, 0x6b, 0x19, 0x98, 0xa2, 0x28, 0xaa, 0xeb, 0x5a, 0x33, 0xef, 0xf1, 0x4e,
|
||||
0x29, 0x86, 0xbf, 0x70, 0x08, 0xfd, 0x34, 0x8a, 0x8c, 0x6d, 0xef, 0xc4, 0xa1, 0xfe, 0xdf, 0x4d,
|
||||
0xeb, 0xf0, 0x2c, 0x4c, 0xf5, 0xb3, 0xe8, 0xf8, 0xc3, 0x45, 0xc7, 0x6b, 0x59, 0x1c, 0x9b, 0xd9,
|
||||
0x52, 0xdf, 0x65, 0x87, 0x18, 0xd2, 0x6d, 0xff, 0x8b, 0x98, 0x2a, 0x97, 0xeb, 0x93, 0xea, 0x6a,
|
||||
0x23, 0x23, 0xc6, 0x32, 0xf5, 0xea, 0x45, 0xe3, 0x99, 0xa0, 0x4d, 0x4b, 0x8f, 0xf8, 0x1d, 0xad,
|
||||
0xa9, 0x97, 0xa2, 0xd6, 0xaf, 0x5e, 0x11, 0xf7, 0x5f, 0x28, 0xfb, 0x38, 0x80, 0x38, 0x50, 0xc4,
|
||||
};
|
||||
|
||||
// Ciphertext of the test case using RSAES-OAEP2048 with SHA256 MD/BGF1 created with openssl.
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 Ct1230RsaesOaep2048MdSha256Mgf1Sha256[] = {
|
||||
0xa7, 0x20, 0xa9, 0x31, 0xb5, 0xad, 0x83, 0x0a, 0x07, 0xee, 0x36, 0x46, 0xa5, 0x78, 0x3a, 0xda,
|
||||
0x9d, 0xdf, 0xe6, 0x05, 0x0f, 0x7c, 0x46, 0xfe, 0x5f, 0xd6, 0x58, 0x16, 0xb6, 0xaa, 0x82, 0x7c,
|
||||
0x58, 0x8a, 0x52, 0x14, 0x12, 0x29, 0x6f, 0x62, 0x80, 0xa7, 0x61, 0xfe, 0x29, 0x72, 0x6f, 0x73,
|
||||
0xf6, 0x2f, 0x54, 0x38, 0x58, 0x7b, 0xbd, 0xa1, 0x2f, 0x9d, 0x12, 0x83, 0x72, 0xbc, 0x3d, 0x29,
|
||||
0x65, 0x39, 0xcb, 0x93, 0x95, 0x3e, 0x73, 0xc9, 0x6f, 0xb9, 0xe8, 0xd5, 0x8b, 0x91, 0x0d, 0x87,
|
||||
0x7e, 0x22, 0xb5, 0x93, 0x3d, 0xa8, 0x4a, 0xd9, 0x1a, 0x13, 0xf7, 0xf4, 0x7f, 0x16, 0x42, 0xfe,
|
||||
0x63, 0x10, 0x7e, 0xa1, 0xe5, 0x04, 0xcf, 0xed, 0x93, 0x2d, 0x16, 0x3b, 0x79, 0x1f, 0x53, 0x41,
|
||||
0xe3, 0xca, 0x69, 0x18, 0x6a, 0xe5, 0xec, 0x9a, 0xce, 0xbc, 0x47, 0xf6, 0x77, 0x9a, 0x5c, 0xea,
|
||||
0xac, 0x7e, 0x28, 0xeb, 0x1e, 0xfe, 0x75, 0xa6, 0xbf, 0x1e, 0xfd, 0x1c, 0x63, 0x69, 0x47, 0x04,
|
||||
0xaf, 0x69, 0x7e, 0x1c, 0xa1, 0x7f, 0x00, 0xcf, 0xec, 0x16, 0x34, 0xd9, 0xde, 0x91, 0x0e, 0x0f,
|
||||
0x0b, 0x1e, 0x66, 0xc3, 0x41, 0x88, 0x43, 0xbe, 0xa3, 0x2a, 0x7c, 0x87, 0xff, 0xc0, 0x67, 0xdc,
|
||||
0xc7, 0xeb, 0x28, 0x07, 0x00, 0x72, 0x85, 0x17, 0xca, 0x05, 0x9f, 0x29, 0x6b, 0xad, 0xc6, 0xae,
|
||||
0x1c, 0x4a, 0xf2, 0xfe, 0x97, 0xc7, 0x6e, 0x4b, 0xbf, 0xfd, 0x46, 0xbe, 0xf8, 0x76, 0xc9, 0x70,
|
||||
0x58, 0x3a, 0x73, 0xcc, 0x34, 0xda, 0xfe, 0x5b, 0x6d, 0x98, 0x74, 0x95, 0x85, 0xc7, 0xc9, 0x84,
|
||||
0x02, 0xa8, 0x97, 0x13, 0xa3, 0x83, 0xcb, 0x28, 0x3d, 0xbb, 0x2b, 0x3b, 0x45, 0xf1, 0x6e, 0xc5,
|
||||
0x37, 0x23, 0x21, 0xe6, 0x74, 0x2d, 0x48, 0x19, 0x97, 0xaf, 0xee, 0x3d, 0x9b, 0xd0, 0x05, 0xc7
|
||||
};
|
||||
|
||||
typedef struct _OAEP_ENC_DEC_TEST_CONTEXT OAEP_ENC_DEC_TEST_CONTEXT;
|
||||
typedef
|
||||
BOOLEAN
|
||||
(EFIAPI *OAEP_TEST_ENCRYPT)(
|
||||
IN OAEP_ENC_DEC_TEST_CONTEXT *TestContext,
|
||||
IN CONST UINT8 *ClearText,
|
||||
IN UINTN ClearTextSize,
|
||||
IN CONST UINT8 *PrngSeed,
|
||||
IN UINTN PrngSeedSize,
|
||||
IN UINT16 DigestLen,
|
||||
OUT UINT8 **CipherText,
|
||||
OUT UINTN *CipherTextSize
|
||||
);
|
||||
|
||||
typedef
|
||||
BOOLEAN
|
||||
(EFIAPI *OAEP_TEST_DECRYPT)(
|
||||
IN OAEP_ENC_DEC_TEST_CONTEXT *TestContext,
|
||||
IN CONST UINT8 *CipherText,
|
||||
IN UINTN CipherTextSize,
|
||||
IN UINT16 DigestLen,
|
||||
OUT UINT8 **ClearText,
|
||||
OUT UINTN *ClearTextSize
|
||||
);
|
||||
|
||||
typedef struct _OAEP_ENC_DEC_TEST_CONTEXT {
|
||||
CONST UINT8 *SelfTestCert;
|
||||
UINTN SelfTestCertSize;
|
||||
CONST UINT8 *PrivateKey;
|
||||
UINTN PrivateKeySize;
|
||||
CONST UINT8 *RsaN;
|
||||
UINTN RsaNSize;
|
||||
CONST UINT8 *RsaE;
|
||||
UINTN RsaESize;
|
||||
CONST UINT8 *RsaD;
|
||||
UINTN RsaDSize;
|
||||
CONST UINT8 *PrngSeed;
|
||||
UINTN PrngSeedSize;
|
||||
CONST UINT8 *ClearText;
|
||||
UINTN ClearTextSize;
|
||||
CONST UINT8 *CipherText;
|
||||
UINTN CipherTextSize;
|
||||
UINT16 DigestLen;
|
||||
OAEP_TEST_ENCRYPT Encrypt;
|
||||
OAEP_TEST_DECRYPT Decrypt;
|
||||
UNIT_TEST_STATUS Expect;
|
||||
} OAEP_ENC_DEC_TEST_CONTEXT;
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CallPkcs1v2Encrypt (
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx,
|
||||
CONST UINT8 *ClearText,
|
||||
UINTN ClearTextSize,
|
||||
CONST UINT8 *PrngSeed,
|
||||
UINTN PrngSeedSize,
|
||||
UINT16 DigestLen,
|
||||
UINT8 **CipherText,
|
||||
UINTN *CipherTextSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
|
||||
Status = Pkcs1v2Encrypt (
|
||||
TestCtx->SelfTestCert,
|
||||
TestCtx->SelfTestCertSize,
|
||||
(UINT8 *)ClearText,
|
||||
ClearTextSize,
|
||||
PrngSeed,
|
||||
PrngSeedSize,
|
||||
CipherText,
|
||||
CipherTextSize
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CallPkcs1v2Decrypt (
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx,
|
||||
CONST UINT8 *CipherText,
|
||||
UINTN CipherTextSize,
|
||||
UINT16 DigestLen,
|
||||
UINT8 **ClearText,
|
||||
UINTN *ClearTextSize
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
|
||||
Status = Pkcs1v2Decrypt (
|
||||
TestCtx->PrivateKey,
|
||||
TestCtx->PrivateKeySize,
|
||||
(UINT8 *)CipherText,
|
||||
CipherTextSize,
|
||||
ClearText,
|
||||
ClearTextSize
|
||||
);
|
||||
return Status;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CallRsaOaepEncrypt (
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx,
|
||||
CONST UINT8 *ClearText,
|
||||
UINTN ClearTextSize,
|
||||
CONST UINT8 *RandSeedIn,
|
||||
UINTN RandSeedSizeIn,
|
||||
UINT16 DigestLen,
|
||||
UINT8 **CipherText,
|
||||
UINTN *CipherTextSize
|
||||
)
|
||||
{
|
||||
VOID *RsaContext = NULL;
|
||||
BOOLEAN Status;
|
||||
|
||||
RsaContext = RsaNew ();
|
||||
UT_ASSERT_FALSE (RsaContext == NULL);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyN, TestCtx->RsaN, TestCtx->RsaNSize);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyE, TestCtx->RsaE, TestCtx->RsaESize);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaOaepEncrypt (
|
||||
RsaContext,
|
||||
(UINT8 *)ClearText,
|
||||
ClearTextSize,
|
||||
RandSeedIn,
|
||||
RandSeedSizeIn,
|
||||
DigestLen,
|
||||
CipherText,
|
||||
CipherTextSize
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
CallRsaOaepDecrypt (
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx,
|
||||
CONST UINT8 *CipherText,
|
||||
UINTN CipherTextSize,
|
||||
UINT16 DigestLen,
|
||||
UINT8 **ClearText,
|
||||
UINTN *ClearTextSize
|
||||
)
|
||||
{
|
||||
VOID *RsaContext = NULL;
|
||||
BOOLEAN Status;
|
||||
|
||||
RsaContext = RsaNew ();
|
||||
UT_ASSERT_FALSE (RsaContext == NULL);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyN, TestCtx->RsaN, TestCtx->RsaNSize);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyE, TestCtx->RsaE, TestCtx->RsaESize);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyD, TestCtx->RsaD, TestCtx->RsaDSize);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaOaepDecrypt (
|
||||
RsaContext,
|
||||
(UINT8 *)CipherText,
|
||||
CipherTextSize,
|
||||
DigestLen,
|
||||
ClearText,
|
||||
ClearTextSize
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
UNIT_TEST_STATUS
|
||||
EFIAPI
|
||||
TestVerifyOaepEncrypt (
|
||||
TestVerifyEncrypt (
|
||||
IN UNIT_TEST_CONTEXT Context
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 *OutBuffer = NULL;
|
||||
UINTN OutBufferSize = 0;
|
||||
UINT8 *OutBuffer2 = NULL;
|
||||
UINTN OutBuffer2Size = 0;
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx;
|
||||
|
||||
TestCtx = (OAEP_ENC_DEC_TEST_CONTEXT *)Context;
|
||||
|
||||
Status = TestCtx->Encrypt (
|
||||
TestCtx,
|
||||
TestCtx->ClearText,
|
||||
TestCtx->ClearTextSize,
|
||||
TestCtx->PrngSeed,
|
||||
TestCtx->PrngSeedSize,
|
||||
TestCtx->DigestLen,
|
||||
&OutBuffer,
|
||||
&OutBufferSize
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = TestCtx->Encrypt (
|
||||
TestCtx,
|
||||
TestCtx->ClearText,
|
||||
TestCtx->ClearTextSize,
|
||||
TestCtx->PrngSeed,
|
||||
TestCtx->PrngSeedSize,
|
||||
TestCtx->DigestLen,
|
||||
&OutBuffer2,
|
||||
&OutBuffer2Size
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
// TRUE - the two OutBuffers are indentical. That means the Oaep encrypt result is incorrect.
|
||||
Status = (CompareMem (OutBuffer, OutBuffer2, OutBufferSize >= OutBuffer2Size ? OutBufferSize : OutBuffer2Size) == 0);
|
||||
UT_ASSERT_FALSE (Status);
|
||||
|
||||
if (OutBuffer) {
|
||||
FreePool (OutBuffer);
|
||||
OutBuffer = NULL;
|
||||
OutBufferSize = 0;
|
||||
}
|
||||
|
||||
if (OutBuffer2) {
|
||||
FreePool (OutBuffer2);
|
||||
OutBuffer2 = NULL;
|
||||
OutBuffer2Size = 0;
|
||||
}
|
||||
|
||||
return UNIT_TEST_PASSED;
|
||||
}
|
||||
|
||||
UNIT_TEST_STATUS
|
||||
EFIAPI
|
||||
TestVerifyDecrypt (
|
||||
IN UNIT_TEST_CONTEXT Context
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 *OutBuffer = NULL;
|
||||
UINTN OutBufferSize = 0;
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx;
|
||||
|
||||
TestCtx = Context;
|
||||
|
||||
Status = TestCtx->Decrypt (
|
||||
TestCtx,
|
||||
TestCtx->CipherText,
|
||||
TestCtx->CipherTextSize,
|
||||
TestCtx->DigestLen,
|
||||
&OutBuffer,
|
||||
&OutBufferSize
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
UT_ASSERT_TRUE (CompareMem (OutBuffer, TestCtx->ClearText, OutBufferSize >= TestCtx->ClearTextSize ? OutBufferSize : TestCtx->ClearTextSize) == 0);
|
||||
UT_ASSERT_TRUE (OutBufferSize == TestCtx->ClearTextSize);
|
||||
|
||||
if (OutBuffer) {
|
||||
FreePool (OutBuffer);
|
||||
OutBuffer = NULL;
|
||||
OutBufferSize = 0;
|
||||
}
|
||||
|
||||
return UNIT_TEST_PASSED;
|
||||
}
|
||||
|
||||
UNIT_TEST_STATUS
|
||||
EFIAPI
|
||||
TestVerifyEncryptDecrypt (
|
||||
IN UNIT_TEST_CONTEXT Context
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 *ClearText = NULL;
|
||||
UINTN ClearTextSize = 0;
|
||||
UINT8 *CipherText = NULL;
|
||||
UINTN CipherTextSize = 0;
|
||||
OAEP_ENC_DEC_TEST_CONTEXT *TestCtx;
|
||||
|
||||
TestCtx = Context;
|
||||
|
||||
Status = TestCtx->Encrypt (
|
||||
TestCtx,
|
||||
TestCtx->ClearText,
|
||||
TestCtx->ClearTextSize,
|
||||
TestCtx->PrngSeed,
|
||||
TestCtx->PrngSeedSize,
|
||||
TestCtx->DigestLen,
|
||||
&CipherText,
|
||||
&CipherTextSize
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = TestCtx->Decrypt (
|
||||
TestCtx,
|
||||
CipherText,
|
||||
CipherTextSize,
|
||||
TestCtx->DigestLen,
|
||||
&ClearText,
|
||||
&ClearTextSize
|
||||
);
|
||||
|
||||
if (TestCtx->Expect == UNIT_TEST_PASSED) {
|
||||
UT_ASSERT_TRUE (Status);
|
||||
} else {
|
||||
UT_ASSERT_FALSE (Status);
|
||||
}
|
||||
|
||||
if (TestCtx->Expect == UNIT_TEST_PASSED) {
|
||||
UT_ASSERT_TRUE (CompareMem (ClearText, TestCtx->ClearText, ClearTextSize >= TestCtx->ClearTextSize ? ClearTextSize : TestCtx->ClearTextSize) == 0);
|
||||
UT_ASSERT_TRUE (ClearTextSize == TestCtx->ClearTextSize);
|
||||
}
|
||||
|
||||
if (CipherText) {
|
||||
FreePool (CipherText);
|
||||
CipherText = NULL;
|
||||
CipherTextSize = 0;
|
||||
}
|
||||
|
||||
if (ClearText) {
|
||||
FreePool (ClearText);
|
||||
ClearText = NULL;
|
||||
ClearTextSize = 0;
|
||||
}
|
||||
|
||||
return UNIT_TEST_PASSED;
|
||||
}
|
||||
|
||||
UNIT_TEST_STATUS
|
||||
EFIAPI
|
||||
TestVerifyPkcs1v2EncryptInterface (
|
||||
IN UNIT_TEST_CONTEXT Context
|
||||
)
|
||||
{
|
||||
BOOLEAN Status;
|
||||
UINT8 File[4];
|
||||
UINT8 *OutBuffer;
|
||||
UINTN OutBufferSize;
|
||||
UINT8 *OutBuffer2;
|
||||
UINTN OutBuffer2Size;
|
||||
|
||||
// Create a file and add content '123' in it
|
||||
File[0] = '1';
|
||||
File[1] = '2';
|
||||
File[2] = '3';
|
||||
File[3] = 0;
|
||||
|
||||
OutBuffer = NULL;
|
||||
OutBufferSize = 0;
|
||||
OutBuffer2 = NULL;
|
||||
OutBuffer2Size = 0;
|
||||
|
||||
Status = Pkcs1v2Encrypt (
|
||||
SelfTestCert,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINTN)sizeof (File),
|
||||
NULL,
|
||||
0,
|
||||
&OutBuffer,
|
||||
(UINTN *)&OutBufferSize
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = Pkcs1v2Encrypt (
|
||||
SelfTestCert,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
&OutBuffer2,
|
||||
(UINTN *)&OutBuffer2Size
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
// TRUE - the two OutBuffers are indentical. That means the Oaep encrypt result is incorrect.
|
||||
Status = (CompareMem (OutBuffer, OutBuffer2, OutBufferSize >= OutBuffer2Size ? OutBufferSize : OutBuffer2Size) == 0);
|
||||
UT_ASSERT_FALSE (Status);
|
||||
|
||||
if (OutBuffer) {
|
||||
FreePool (OutBuffer);
|
||||
OutBuffer = NULL;
|
||||
OutBufferSize = 0;
|
||||
}
|
||||
|
||||
if (OutBuffer2) {
|
||||
FreePool (OutBuffer2);
|
||||
OutBuffer2 = NULL;
|
||||
OutBuffer2Size = 0;
|
||||
}
|
||||
|
||||
Status = Pkcs1v2Encrypt (
|
||||
SelfTestCert,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINTN)4,
|
||||
RandSeed,
|
||||
(UINTN)sizeof (RandSeed),
|
||||
&OutBuffer,
|
||||
(UINTN *)&OutBufferSize
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = Pkcs1v2Encrypt (
|
||||
SelfTestCert,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINTN)4,
|
||||
RandSeed,
|
||||
(UINTN)sizeof (RandSeed),
|
||||
&OutBuffer2,
|
||||
(UINTN *)&OutBuffer2Size
|
||||
);
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
// TRUE - the two OutBuffers are indentical. That means the Oaep encrypt result is incorrect.
|
||||
Status = (CompareMem (OutBuffer, OutBuffer2, OutBufferSize >= OutBuffer2Size ? OutBufferSize : OutBuffer2Size) == 0);
|
||||
UT_ASSERT_FALSE (Status);
|
||||
|
||||
if (OutBuffer) {
|
||||
FreePool (OutBuffer);
|
||||
OutBuffer = NULL;
|
||||
OutBufferSize = 0;
|
||||
}
|
||||
|
||||
if (OutBuffer2) {
|
||||
FreePool (OutBuffer2);
|
||||
OutBuffer2 = NULL;
|
||||
OutBuffer2Size = 0;
|
||||
}
|
||||
|
||||
Status = Pkcs1v2Encrypt (
|
||||
NULL,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINT8 *)Msg1230,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
@ -272,7 +601,7 @@ TestVerifyOaepEncrypt (
|
||||
Status = Pkcs1v2Encrypt (
|
||||
SelfTestCert,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINT8 *)Msg1230,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
@ -284,7 +613,7 @@ TestVerifyOaepEncrypt (
|
||||
Status = Pkcs1v2Encrypt (
|
||||
SelfTestCert,
|
||||
(UINTN)sizeof (SelfTestCert),
|
||||
File,
|
||||
(UINT8 *)Msg1230,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
@ -296,11 +625,298 @@ TestVerifyOaepEncrypt (
|
||||
return UNIT_TEST_PASSED;
|
||||
}
|
||||
|
||||
UNIT_TEST_STATUS
|
||||
EFIAPI
|
||||
TestVerifyRsaOaepEncryptInterface (
|
||||
IN UNIT_TEST_CONTEXT Context
|
||||
)
|
||||
{
|
||||
VOID *RsaContext = NULL;
|
||||
BOOLEAN Status;
|
||||
UINT8 *OutBuffer;
|
||||
UINTN OutBufferSize;
|
||||
|
||||
RsaContext = RsaNew ();
|
||||
UT_ASSERT_FALSE (RsaContext == NULL);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyN, RsaN, sizeof (RsaN));
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaSetKey (RsaContext, RsaKeyE, RsaE, sizeof (RsaE));
|
||||
UT_ASSERT_TRUE (Status);
|
||||
|
||||
Status = RsaOaepEncrypt (
|
||||
NULL,
|
||||
(UINT8 *)Msg1230,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
&OutBuffer,
|
||||
(UINTN *)&OutBufferSize
|
||||
);
|
||||
UT_ASSERT_FALSE (Status);
|
||||
|
||||
Status = RsaOaepEncrypt (
|
||||
RsaContext,
|
||||
(UINT8 *)Msg1230,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
(UINT8 **)NULL,
|
||||
(UINTN *)&OutBufferSize
|
||||
);
|
||||
UT_ASSERT_FALSE (Status);
|
||||
|
||||
Status = RsaOaepEncrypt (
|
||||
RsaContext,
|
||||
(UINT8 *)Msg1230,
|
||||
(UINTN)4,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
&OutBuffer,
|
||||
(UINTN *)NULL
|
||||
);
|
||||
UT_ASSERT_FALSE (Status);
|
||||
|
||||
return UNIT_TEST_PASSED;
|
||||
}
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyPkcs1v2Msg1230 = {
|
||||
.SelfTestCert = SelfTestCert,
|
||||
.SelfTestCertSize = sizeof (SelfTestCert),
|
||||
.PrivateKey = PrivateKey,
|
||||
.PrivateKeySize = sizeof (PrivateKey),
|
||||
.RsaN = NULL,
|
||||
.RsaNSize = 0,
|
||||
.RsaE = NULL,
|
||||
.RsaESize = 0,
|
||||
.RsaD = NULL,
|
||||
.RsaDSize = 0,
|
||||
.PrngSeed = NULL,
|
||||
.PrngSeedSize = 0,
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallPkcs1v2Encrypt,
|
||||
.Decrypt = CallPkcs1v2Decrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyPkcs1v2Msg1230PrngSeed = {
|
||||
.SelfTestCert = SelfTestCert,
|
||||
.SelfTestCertSize = sizeof (SelfTestCert),
|
||||
.PrivateKey = PrivateKey,
|
||||
.PrivateKeySize = sizeof (PrivateKey),
|
||||
.RsaN = NULL,
|
||||
.RsaNSize = 0,
|
||||
.RsaE = NULL,
|
||||
.RsaESize = 0,
|
||||
.RsaD = NULL,
|
||||
.RsaDSize = 0,
|
||||
.PrngSeed = RandSeed,
|
||||
.PrngSeedSize = sizeof (RandSeed),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallPkcs1v2Encrypt,
|
||||
.Decrypt = CallPkcs1v2Decrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyRsaOaepMsg1230 = {
|
||||
.SelfTestCert = NULL,
|
||||
.SelfTestCertSize = 0,
|
||||
.PrivateKey = NULL,
|
||||
.PrivateKeySize = 0,
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.PrngSeed = NULL,
|
||||
.PrngSeedSize = 0,
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallRsaOaepEncrypt,
|
||||
.Decrypt = CallRsaOaepDecrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyRsaOaepMsg1230PrngSeed = {
|
||||
.SelfTestCert = NULL,
|
||||
.SelfTestCertSize = 0,
|
||||
.PrivateKey = NULL,
|
||||
.PrivateKeySize = 0,
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.PrngSeed = RandSeed,
|
||||
.PrngSeedSize = sizeof (RandSeed),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallRsaOaepEncrypt,
|
||||
.Decrypt = CallRsaOaepDecrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyPkcs1v2EncryptRsaOaepDecrypt = {
|
||||
.SelfTestCert = SelfTestCert,
|
||||
.SelfTestCertSize = sizeof (SelfTestCert),
|
||||
.PrivateKey = PrivateKey,
|
||||
.PrivateKeySize = sizeof (PrivateKey),
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallPkcs1v2Encrypt,
|
||||
.Decrypt = CallRsaOaepDecrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyRsaOaepEncryptPkcs1v2Decrypt = {
|
||||
.SelfTestCert = SelfTestCert,
|
||||
.SelfTestCertSize = sizeof (SelfTestCert),
|
||||
.PrivateKey = PrivateKey,
|
||||
.PrivateKeySize = sizeof (PrivateKey),
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallRsaOaepEncrypt,
|
||||
.Decrypt = CallPkcs1v2Decrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyRsaesOaep2048MdDefaultBgf1Default = {
|
||||
.SelfTestCert = NULL,
|
||||
.SelfTestCertSize = 0,
|
||||
.PrivateKey = NULL,
|
||||
.PrivateKeySize = 0,
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = 0,
|
||||
.Encrypt = CallRsaOaepEncrypt,
|
||||
.Decrypt = CallRsaOaepDecrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyRsaesOaep2048MdSha1Mgf1Sha1 = {
|
||||
.SelfTestCert = NULL,
|
||||
.SelfTestCertSize = 0,
|
||||
.PrivateKey = NULL,
|
||||
.PrivateKeySize = 0,
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaepMdSha1Mgf1Sha1,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaepMdSha1Mgf1Sha1),
|
||||
.DigestLen = SHA1_DIGEST_SIZE,
|
||||
.Encrypt = CallRsaOaepEncrypt,
|
||||
.Decrypt = CallRsaOaepDecrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
OAEP_ENC_DEC_TEST_CONTEXT mTestVerifyRsaesOaep2048MdSha256Mgf1Sha256 = {
|
||||
.SelfTestCert = NULL,
|
||||
.SelfTestCertSize = 0,
|
||||
.PrivateKey = NULL,
|
||||
.PrivateKeySize = 0,
|
||||
.RsaN = RsaN,
|
||||
.RsaNSize = sizeof (RsaN),
|
||||
.RsaE = RsaE,
|
||||
.RsaESize = sizeof (RsaE),
|
||||
.RsaD = RsaD,
|
||||
.RsaDSize = sizeof (RsaD),
|
||||
.ClearText = Msg1230,
|
||||
.ClearTextSize = sizeof (Msg1230),
|
||||
.CipherText = Ct1230RsaesOaep2048MdSha256Mgf1Sha256,
|
||||
.CipherTextSize = sizeof (Ct1230RsaesOaep2048MdSha256Mgf1Sha256),
|
||||
.DigestLen = SHA256_DIGEST_SIZE,
|
||||
.Encrypt = CallRsaOaepEncrypt,
|
||||
.Decrypt = CallRsaOaepDecrypt,
|
||||
.Expect = UNIT_TEST_PASSED
|
||||
};
|
||||
|
||||
TEST_DESC mOaepTest[] = {
|
||||
//
|
||||
// -----Description--------------------------------------Class----------------------Function-----------------Pre---Post--Context
|
||||
//
|
||||
{ "TestVerifyOaepEncrypt()", "CryptoPkg.BaseCryptLib.Pkcs1v2Encrypt", TestVerifyOaepEncrypt, NULL, NULL, NULL },
|
||||
// Pkcs1v2Encrypt / Decrypt
|
||||
{ "Pkcs1v2Encrypt (Interface)", "CryptoPkg.BaseCryptLib.Pkcs1v2Encrypt.Interface", TestVerifyPkcs1v2EncryptInterface, NULL, NULL, &mTestVerifyPkcs1v2Msg1230 },
|
||||
{ "Pkcs1v2Encrypt (NoSeed)", "CryptoPkg.BaseCryptLib.Pkcs1v2Encrypt.NoSeed", TestVerifyEncrypt, NULL, NULL, &mTestVerifyPkcs1v2Msg1230 },
|
||||
{ "Pkcs1v2Encrypt (Seeded)", "CryptoPkg.BaseCryptLib.Pkcs1v2Encrypt.Seeded", TestVerifyEncrypt, NULL, NULL, &mTestVerifyPkcs1v2Msg1230PrngSeed },
|
||||
{ "Pkcs1v2Decrypt", "CryptoPkg.BaseCryptLib.Pkcs1v2Decrypt", TestVerifyDecrypt, NULL, NULL, &mTestVerifyPkcs1v2Msg1230 },
|
||||
{ "Pkcs1v2EncryptDecrypt", "CryptoPkg.BaseCryptLib.Pkcs1v2EncryptDecrypt", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyPkcs1v2Msg1230 },
|
||||
|
||||
// RsaOaepEncrypt / Decrypt
|
||||
{ "RsaOaepEncrypt (Interface)", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt.Interface", TestVerifyRsaOaepEncryptInterface, NULL, NULL, &mTestVerifyRsaOaepMsg1230 },
|
||||
{ "RsaOaepEncrypt (NoSeed)", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt.NoSeed", TestVerifyEncrypt, NULL, NULL, &mTestVerifyRsaOaepMsg1230 },
|
||||
{ "RsaOaepEncrypt (Seeded)", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt.Seeded", TestVerifyEncrypt, NULL, NULL, &mTestVerifyRsaOaepMsg1230PrngSeed },
|
||||
{ "RsaOaepDecrypt", "CryptoPkg.BaseCryptLib.RsaOaepDecrypt", TestVerifyDecrypt, NULL, NULL, &mTestVerifyRsaOaepMsg1230 },
|
||||
{ "RsaOaepEncryptDecrypt", "CryptoPkg.BaseCryptLib.RsaOaepEncryptDecrypt", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyRsaOaepMsg1230 },
|
||||
|
||||
// Mix interfaces
|
||||
{ "RsaOaepEncryptPkcs1v2Decrypt", "CryptoPkg.BaseCryptLib.RsaOaepEncryptPkcs1v2Decrypt", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyRsaOaepEncryptPkcs1v2Decrypt },
|
||||
{ "Pkcs1v2EncryptRsaOaepDecrypt", "CryptoPkg.BaseCryptLib.Pkcs1v2EncryptRsaOaepDecrypt", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyPkcs1v2EncryptRsaOaepDecrypt },
|
||||
|
||||
// Message digest default / MGF1 default (SHA1)
|
||||
{ "RsaOaepEncrypt (MdDefaultMgf1Default)", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt.MdDefaultMgf1Default", TestVerifyEncrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdDefaultBgf1Default },
|
||||
{ "RsaOaepDecrypt (MdDefaultMgf1Default)", "CryptoPkg.BaseCryptLib.RsaOaepDecrypt.MdDefaultMgf1Default", TestVerifyDecrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdDefaultBgf1Default },
|
||||
{ "RsaOaepEncryptDecrypt (MdDefaultMgf1Default)", "CryptoPkg.BaseCryptLib.RsaOaepEncryptDecrypt.MdDefaultMgf1Default", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdDefaultBgf1Default },
|
||||
|
||||
// Message digest SHA1 / MGF1 SHA1
|
||||
{ "RsaOaepEncrypt (MdSha1Bgf1Sha1", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt.MdSha1Bgf1Sha1", TestVerifyEncrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdSha1Mgf1Sha1 },
|
||||
{ "RsaOaepDecrypt (MdSha1Bgf1Sha1)", "CryptoPkg.BaseCryptLib.RsaOaepDecrypt.MdSha1Bgf1Sha1", TestVerifyDecrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdSha1Mgf1Sha1 },
|
||||
{ "RsaOaepEncryptDecrypt (MdSha1Bgf1Sha1)", "CryptoPkg.BaseCryptLib.RsaOaepEncryptDecrypt.MdSha1Bgf1Sha1", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdSha1Mgf1Sha1 },
|
||||
|
||||
// Message digest SHA256 / MGF1 SHA256
|
||||
{ "RsaOaepEncrypt (MdSha256Bgf1Sha256)", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt.MdSha256Bgf1Sha256", TestVerifyEncrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdSha256Mgf1Sha256 },
|
||||
{ "RsaOaepDecrypt (MdSha256Bgf1Sha256)", "CryptoPkg.BaseCryptLib.RsaOaepDecrypt.MdSha256Bgf1Sha256", TestVerifyDecrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdSha256Mgf1Sha256 },
|
||||
{ "RsaOaepEncryptDecrypt (MdSha256Bgf1Sha256)", "CryptoPkg.BaseCryptLib.RsaOaepEncryptDecryptMdSha256Bgf1Sha256", TestVerifyEncryptDecrypt, NULL, NULL, &mTestVerifyRsaesOaep2048MdSha256Mgf1Sha256 },
|
||||
};
|
||||
|
||||
UINTN mOaepTestNum = ARRAY_SIZE (mOaepTest);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2017 - 2023, Arm Limited. All rights reserved.<BR>
|
||||
Copyright (c) 2017 - 2024, Arm Limited. All rights reserved.<BR>
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
@ -317,7 +317,10 @@ typedef struct CmArmSerialPortInfo {
|
||||
/// The physical base address for the serial port
|
||||
UINT64 BaseAddress;
|
||||
|
||||
/// The serial port interrupt
|
||||
/** The serial port interrupt.
|
||||
0 indicates that the serial port does not
|
||||
have an interrupt wired.
|
||||
*/
|
||||
UINT32 Interrupt;
|
||||
|
||||
/// The serial port baud rate
|
||||
|
@ -2,7 +2,7 @@
|
||||
AML Lib.
|
||||
|
||||
Copyright (c) 2019 - 2023, Arm Limited. All rights reserved.<BR>
|
||||
Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
|
||||
Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights reserved.<BR>
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
@ -1743,6 +1743,45 @@ AmlAddNameStringToNamedPackage (
|
||||
IN AML_OBJECT_NODE_HANDLE NamedNode
|
||||
);
|
||||
|
||||
/** Add an integer value to the named package node.
|
||||
|
||||
AmlCodeGenNamePackage ("_CID", NULL, &PackageNode);
|
||||
AmlGetEisaIdFromString ("PNP0A03", &EisaId);
|
||||
AmlAddIntegerToNamedPackage (EisaId, NameNode);
|
||||
AmlGetEisaIdFromString ("PNP0A08", &EisaId);
|
||||
AmlAddIntegerToNamedPackage (EisaId, NameNode);
|
||||
|
||||
equivalent of the following ASL code:
|
||||
Name (_CID, Package (0x02) // _CID: Compatible ID
|
||||
{
|
||||
EisaId ("PNP0A03"),
|
||||
EisaId ("PNP0A08")
|
||||
})
|
||||
|
||||
The package is added at the tail of the list of the input package node
|
||||
name:
|
||||
Name ("NamePackageNode", Package () {
|
||||
[Pre-existing package entries],
|
||||
[Newly created integer entry]
|
||||
})
|
||||
|
||||
|
||||
@ingroup CodeGenApis
|
||||
|
||||
@param [in] Integer Integer value that need to be added to package node.
|
||||
@param [in, out] NameNode Package named node to add the object to.
|
||||
|
||||
@retval EFI_SUCCESS Success.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@retval Others Error occurred during the operation.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AmlAddIntegerToNamedPackage (
|
||||
IN UINT32 Integer,
|
||||
IN OUT AML_OBJECT_NODE_HANDLE NameNode
|
||||
);
|
||||
|
||||
/** AML code generation to invoke/call another method.
|
||||
|
||||
This method is a subset implementation of MethodInvocation
|
||||
|
@ -1072,6 +1072,7 @@ CreateAmlProcessorContainer (
|
||||
@param [in] IsLeaf The ProcNode is a leaf.
|
||||
@param [in] NodeToken NodeToken of the ProcNode.
|
||||
@param [in] ParentNodeToken Parent NodeToken of the ProcNode.
|
||||
@param [in] PackageNodeSeen A parent of the ProcNode has the physical package flag set.
|
||||
|
||||
@retval EFI_SUCCESS Success.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@ -1083,23 +1084,24 @@ CheckProcNode (
|
||||
UINT32 NodeFlags,
|
||||
BOOLEAN IsLeaf,
|
||||
CM_OBJECT_TOKEN NodeToken,
|
||||
CM_OBJECT_TOKEN ParentNodeToken
|
||||
CM_OBJECT_TOKEN ParentNodeToken,
|
||||
BOOLEAN PackageNodeSeen
|
||||
)
|
||||
{
|
||||
BOOLEAN InvalidFlags;
|
||||
BOOLEAN HasPhysicalPackageBit;
|
||||
BOOLEAN IsTopLevelNode;
|
||||
|
||||
HasPhysicalPackageBit = (NodeFlags & EFI_ACPI_6_3_PPTT_PACKAGE_PHYSICAL) ==
|
||||
EFI_ACPI_6_3_PPTT_PACKAGE_PHYSICAL;
|
||||
IsTopLevelNode = (ParentNodeToken == CM_NULL_TOKEN);
|
||||
|
||||
// A top-level node is a Physical Package and conversely.
|
||||
InvalidFlags = HasPhysicalPackageBit ^ IsTopLevelNode;
|
||||
// Only one Physical Package flag is allowed in the hierarchy
|
||||
InvalidFlags = HasPhysicalPackageBit && PackageNodeSeen;
|
||||
|
||||
// Check Leaf specific flags.
|
||||
if (IsLeaf) {
|
||||
InvalidFlags |= ((NodeFlags & PPTT_LEAF_MASK) != PPTT_LEAF_MASK);
|
||||
// Must have Physical Package flag somewhere in the hierarchy
|
||||
InvalidFlags |= !(HasPhysicalPackageBit || PackageNodeSeen);
|
||||
} else {
|
||||
InvalidFlags |= ((NodeFlags & PPTT_LEAF_MASK) != 0);
|
||||
}
|
||||
@ -1130,6 +1132,7 @@ CheckProcNode (
|
||||
node to.
|
||||
@param [in,out] ProcContainerIndex Pointer to the current processor container
|
||||
index to be used as UID.
|
||||
@param [in] PackageNodeSeen A parent of the ProcNode has the physical package flag set.
|
||||
|
||||
@retval EFI_SUCCESS Success.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@ -1143,7 +1146,8 @@ CreateAmlCpuTopologyTree (
|
||||
IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
|
||||
IN CM_OBJECT_TOKEN NodeToken,
|
||||
IN AML_NODE_HANDLE ParentNode,
|
||||
IN OUT UINT32 *ProcContainerIndex
|
||||
IN OUT UINT32 *ProcContainerIndex,
|
||||
IN BOOLEAN PackageNodeSeen
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
@ -1153,6 +1157,7 @@ CreateAmlCpuTopologyTree (
|
||||
AML_OBJECT_NODE_HANDLE ProcContainerNode;
|
||||
UINT32 Uid;
|
||||
UINT16 Name;
|
||||
BOOLEAN HasPhysicalPackageBit;
|
||||
|
||||
ASSERT (Generator != NULL);
|
||||
ASSERT (Generator->ProcNodeList != NULL);
|
||||
@ -1175,7 +1180,8 @@ CreateAmlCpuTopologyTree (
|
||||
Generator->ProcNodeList[Index].Flags,
|
||||
TRUE,
|
||||
Generator->ProcNodeList[Index].Token,
|
||||
NodeToken
|
||||
NodeToken,
|
||||
PackageNodeSeen
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT (0);
|
||||
@ -1208,7 +1214,8 @@ CreateAmlCpuTopologyTree (
|
||||
Generator->ProcNodeList[Index].Flags,
|
||||
FALSE,
|
||||
Generator->ProcNodeList[Index].Token,
|
||||
NodeToken
|
||||
NodeToken,
|
||||
PackageNodeSeen
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT (0);
|
||||
@ -1249,13 +1256,17 @@ CreateAmlCpuTopologyTree (
|
||||
ProcContainerName++;
|
||||
}
|
||||
|
||||
HasPhysicalPackageBit = (Generator->ProcNodeList[Index].Flags & EFI_ACPI_6_3_PPTT_PACKAGE_PHYSICAL) ==
|
||||
EFI_ACPI_6_3_PPTT_PACKAGE_PHYSICAL;
|
||||
|
||||
// Recursively continue creating an AML tree.
|
||||
Status = CreateAmlCpuTopologyTree (
|
||||
Generator,
|
||||
CfgMgrProtocol,
|
||||
Generator->ProcNodeList[Index].Token,
|
||||
ProcContainerNode,
|
||||
ProcContainerIndex
|
||||
ProcContainerIndex,
|
||||
(PackageNodeSeen || HasPhysicalPackageBit)
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT (0);
|
||||
@ -1311,7 +1322,8 @@ CreateTopologyFromProcHierarchy (
|
||||
CfgMgrProtocol,
|
||||
CM_NULL_TOKEN,
|
||||
ScopeNode,
|
||||
&ProcContainerIndex
|
||||
&ProcContainerIndex,
|
||||
FALSE
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT (0);
|
||||
|
@ -3871,6 +3871,73 @@ exit_handler:
|
||||
return Status;
|
||||
}
|
||||
|
||||
/** Add an integer value to the named package node.
|
||||
|
||||
AmlCodeGenNamePackage ("_CID", NULL, &PackageNode);
|
||||
AmlGetEisaIdFromString ("PNP0A03", &EisaId);
|
||||
AmlAddIntegerToNamedPackage (EisaId, NameNode);
|
||||
AmlGetEisaIdFromString ("PNP0A08", &EisaId);
|
||||
AmlAddIntegerToNamedPackage (EisaId, NameNode);
|
||||
|
||||
equivalent of the following ASL code:
|
||||
Name (_CID, Package (0x02) // _CID: Compatible ID
|
||||
{
|
||||
EisaId ("PNP0A03"),
|
||||
EisaId ("PNP0A08")
|
||||
})
|
||||
|
||||
The package is added at the tail of the list of the input package node
|
||||
name:
|
||||
Name ("NamePackageNode", Package () {
|
||||
[Pre-existing package entries],
|
||||
[Newly created integer entry]
|
||||
})
|
||||
|
||||
|
||||
@ingroup CodeGenApis
|
||||
|
||||
@param [in] Integer Integer value that need to be added to package node.
|
||||
@param [in, out] NameNode Package named node to add the object to.
|
||||
|
||||
@retval EFI_SUCCESS Success.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@retval Others Error occurred during the operation.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AmlAddIntegerToNamedPackage (
|
||||
IN UINT32 Integer,
|
||||
IN OUT AML_OBJECT_NODE_HANDLE NameNode
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
AML_OBJECT_NODE *PackageNode;
|
||||
|
||||
if (NameNode == NULL) {
|
||||
ASSERT_EFI_ERROR (FALSE);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
PackageNode = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (
|
||||
NameNode,
|
||||
EAmlParseIndexTerm1
|
||||
);
|
||||
if ((PackageNode == NULL) ||
|
||||
(AmlGetNodeType ((AML_NODE_HANDLE)PackageNode) != EAmlNodeObject) ||
|
||||
(!AmlNodeHasOpCode (PackageNode, AML_PACKAGE_OP, 0)))
|
||||
{
|
||||
ASSERT_EFI_ERROR (FALSE);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Status = AmlAddRegisterOrIntegerToPackage (NULL, Integer, PackageNode);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/** AML code generation to invoke/call another method.
|
||||
|
||||
This method is a subset implementation of MethodInvocation
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user