mirror of
git://nv-tegra.nvidia.com/tegra/kernel-src/nv-kernel-display-driver.git
synced 2025-12-24 10:41:52 +03:00
Compare commits
1 Commits
jetson_38.
...
l4t/l4t-35
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7044b44c2 |
@@ -1,141 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, caste, color, religion, or sexual
|
||||
identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contribute to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the overall
|
||||
community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances of
|
||||
any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address,
|
||||
without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, or to ban temporarily or permanently any
|
||||
contributor for other behaviors that they deem inappropriate, threatening,
|
||||
offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when
|
||||
an individual is representing the project or its community. Examples of representing
|
||||
our community include using an official e-mail address, posting via an official
|
||||
social media account, or acting as an appointed representative at an online or
|
||||
offline event. Representation of a project may be further defined and clarified
|
||||
by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders and moderators responsible for enforcement at
|
||||
GitHub_Conduct@nvidia.com.
|
||||
All complaints will be reviewed and investigated and will result in a response
|
||||
that is deemed necessary and appropriate to the circumstances. Leaders and moderators
|
||||
are obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Moderators who do not follow or enforce the Code of Conduct in good faith
|
||||
may face temporary or permanent repercussions as determined by other members of the
|
||||
community’s leadership.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders and moderators will follow these Community Impact Guidelines
|
||||
in determining the consequences for any action they deem in violation of this
|
||||
Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community moderators, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of
|
||||
actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or permanent
|
||||
ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating an egregious single violation, or a pattern of
|
||||
violation of community standards, including sustained inappropriate behavior,
|
||||
harassment of an individual, or aggression toward or disparagement of classes of
|
||||
individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the
|
||||
community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.1, available at
|
||||
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
||||
[https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
@@ -1,21 +0,0 @@
|
||||
Thank you for all the enthusiasm around open-gpu-kernel-modules.
|
||||
|
||||
## Non-functional (cosmetic) changes
|
||||
|
||||
While we appreciate your enthusiasm, we have decided not to accept non-functional changes such as
|
||||
non-code typo fixes, comment and language adjustments, whitespace changes, and similar.
|
||||
|
||||
Changes going into this codebase incur significant overhead. As such, we want to focus our resources
|
||||
on executable code improvements for now.
|
||||
|
||||
If you have questions, or are unsure about the nature of your desired change, please ask us on the
|
||||
[Discussion boards](https://github.com/NVIDIA/open-gpu-kernel-modules/discussions)!
|
||||
|
||||
## Code style
|
||||
|
||||
We currently do not publish a code style guide, as we have many different components coming together.
|
||||
Please read the existing code in the repository, especially the one surrounding your proposed change,
|
||||
to get a feel for what you should aim for.
|
||||
|
||||
Don't worry too much about it! We are happy to guide you through any neccessary style changes through
|
||||
code review of your PR.
|
||||
987
README.md
987
README.md
@@ -1,987 +0,0 @@
|
||||
# NVIDIA Linux Open GPU Kernel Module Source
|
||||
|
||||
This is the source release of the NVIDIA Linux open GPU kernel modules,
|
||||
version 580.00.
|
||||
|
||||
|
||||
## How to Build
|
||||
|
||||
To build:
|
||||
|
||||
make modules -j$(nproc)
|
||||
|
||||
To install, first uninstall any existing NVIDIA kernel modules. Then,
|
||||
as root:
|
||||
|
||||
make modules_install -j$(nproc)
|
||||
|
||||
Note that the kernel modules built here must be used with GSP
|
||||
firmware and user-space NVIDIA GPU driver components from a corresponding
|
||||
580.00 driver release. This can be achieved by installing
|
||||
the NVIDIA GPU driver from the .run file using the `--no-kernel-modules`
|
||||
option. E.g.,
|
||||
|
||||
sh ./NVIDIA-Linux-[...].run --no-kernel-modules
|
||||
|
||||
|
||||
## Supported Target CPU Architectures
|
||||
|
||||
Currently, the kernel modules can be built for x86_64 or aarch64.
|
||||
If cross-compiling, set these variables on the make command line:
|
||||
|
||||
TARGET_ARCH=aarch64|x86_64
|
||||
CC
|
||||
LD
|
||||
AR
|
||||
CXX
|
||||
OBJCOPY
|
||||
|
||||
E.g.,
|
||||
|
||||
# compile on x86_64 for aarch64
|
||||
make modules -j$(nproc) \
|
||||
TARGET_ARCH=aarch64 \
|
||||
CC=aarch64-linux-gnu-gcc \
|
||||
LD=aarch64-linux-gnu-ld \
|
||||
AR=aarch64-linux-gnu-ar \
|
||||
CXX=aarch64-linux-gnu-g++ \
|
||||
OBJCOPY=aarch64-linux-gnu-objcopy
|
||||
|
||||
|
||||
## Other Build Knobs
|
||||
|
||||
NV_VERBOSE - Set this to "1" to print each complete command executed;
|
||||
otherwise, a succinct "CC" line is printed.
|
||||
|
||||
DEBUG - Set this to "1" to build the kernel modules as debug. By default, the
|
||||
build compiles without debugging information. This also enables
|
||||
various debug log messages in the kernel modules.
|
||||
|
||||
These variables can be set on the make command line. E.g.,
|
||||
|
||||
make modules -j$(nproc) NV_VERBOSE=1
|
||||
|
||||
|
||||
## Supported Toolchains
|
||||
|
||||
Any reasonably modern version of GCC or Clang can be used to build the
|
||||
kernel modules. Note that the kernel interface layers of the kernel
|
||||
modules must be built with the toolchain that was used to build the
|
||||
kernel.
|
||||
|
||||
|
||||
## Supported Linux Kernel Versions
|
||||
|
||||
The NVIDIA open kernel modules support the same range of Linux kernel
|
||||
versions that are supported with the proprietary NVIDIA kernel modules.
|
||||
This is currently Linux kernel 4.15 or newer.
|
||||
|
||||
|
||||
## How to Contribute
|
||||
|
||||
Contributions can be made by creating a pull request on
|
||||
https://github.com/NVIDIA/open-gpu-kernel-modules
|
||||
We'll respond via GitHub.
|
||||
|
||||
Note that when submitting a pull request, you will be prompted to accept
|
||||
a Contributor License Agreement.
|
||||
|
||||
This code base is shared with NVIDIA's proprietary drivers, and various
|
||||
processing is performed on the shared code to produce the source code that is
|
||||
published here. This has several implications for the foreseeable future:
|
||||
|
||||
* The GitHub repository will function mostly as a snapshot of each driver
|
||||
release.
|
||||
|
||||
* We do not expect to be able to provide revision history for individual
|
||||
changes that were made to NVIDIA's shared code base. There will likely
|
||||
only be one git commit per driver release.
|
||||
|
||||
* We may not be able to reflect individual contributions as separate
|
||||
git commits in the GitHub repository.
|
||||
|
||||
* Because the code undergoes various processing prior to publishing here,
|
||||
contributions made here require manual merging to be applied to the shared
|
||||
code base. Therefore, large refactoring changes made here may be difficult to
|
||||
merge and accept back into the shared code base. If you have large
|
||||
refactoring to suggest, please contact us in advance, so we can coordinate.
|
||||
|
||||
|
||||
## How to Report Issues
|
||||
|
||||
Problems specific to the Open GPU Kernel Modules can be reported in the
|
||||
Issues section of the https://github.com/NVIDIA/open-gpu-kernel-modules
|
||||
repository.
|
||||
|
||||
Further, any of the existing bug reporting venues can be used to communicate
|
||||
problems to NVIDIA, such as our forum:
|
||||
|
||||
https://forums.developer.nvidia.com/c/gpu-graphics/linux/148
|
||||
|
||||
or linux-bugs@nvidia.com.
|
||||
|
||||
Please see the 'NVIDIA Contact Info and Additional Resources' section
|
||||
of the NVIDIA GPU Driver README for details.
|
||||
|
||||
Please see the separate [SECURITY.md](SECURITY.md) document if you
|
||||
believe you have discovered a security vulnerability in this software.
|
||||
|
||||
|
||||
## Kernel Interface and OS-Agnostic Components of Kernel Modules
|
||||
|
||||
Most of NVIDIA's kernel modules are split into two components:
|
||||
|
||||
* An "OS-agnostic" component: this is the component of each kernel module
|
||||
that is independent of operating system.
|
||||
|
||||
* A "kernel interface layer": this is the component of each kernel module
|
||||
that is specific to the Linux kernel version and configuration.
|
||||
|
||||
When packaged in the NVIDIA .run installation package, the OS-agnostic
|
||||
component is provided as a binary: it is large and time-consuming to
|
||||
compile, so pre-built versions are provided so that the user does
|
||||
not have to compile it during every driver installation. For the
|
||||
nvidia.ko kernel module, this component is named "nv-kernel.o_binary".
|
||||
For the nvidia-modeset.ko kernel module, this component is named
|
||||
"nv-modeset-kernel.o_binary". Neither nvidia-drm.ko nor nvidia-uvm.ko
|
||||
have OS-agnostic components.
|
||||
|
||||
The kernel interface layer component for each kernel module must be built
|
||||
for the target kernel.
|
||||
|
||||
|
||||
## Directory Structure Layout
|
||||
|
||||
- `kernel-open/` The kernel interface layer
|
||||
- `kernel-open/nvidia/` The kernel interface layer for nvidia.ko
|
||||
- `kernel-open/nvidia-drm/` The kernel interface layer for nvidia-drm.ko
|
||||
- `kernel-open/nvidia-modeset/` The kernel interface layer for nvidia-modeset.ko
|
||||
- `kernel-open/nvidia-uvm/` The kernel interface layer for nvidia-uvm.ko
|
||||
|
||||
- `src/` The OS-agnostic code
|
||||
- `src/nvidia/` The OS-agnostic code for nvidia.ko
|
||||
- `src/nvidia-modeset/` The OS-agnostic code for nvidia-modeset.ko
|
||||
- `src/common/` Utility code used by one or more of nvidia.ko and nvidia-modeset.ko
|
||||
- `nouveau/` Tools for integration with the Nouveau device driver
|
||||
|
||||
|
||||
## Nouveau device driver integration
|
||||
|
||||
The Python script in the 'nouveau' directory is used to extract some of the
|
||||
firmware binary images (and related data) encoded in the source code and
|
||||
store them as distinct files. These files are used by the Nouveau device
|
||||
driver to load and communicate with the GSP firmware.
|
||||
|
||||
The layout of the binary files is described in nouveau_firmware_layout.ods,
|
||||
which is an OpenDocument Spreadsheet file, compatible with most spreadsheet
|
||||
software applications.
|
||||
|
||||
|
||||
## Compatible GPUs
|
||||
|
||||
The NVIDIA open kernel modules can be used on any Turing or later GPU (see the
|
||||
table below).
|
||||
|
||||
For details on feature support and limitations, see the NVIDIA GPU driver
|
||||
end user README here:
|
||||
|
||||
https://us.download.nvidia.com/XFree86/Linux-x86_64/580.00/README/kernel_open.html
|
||||
|
||||
For vGPU support, please refer to the README.vgpu packaged in the vGPU Host
|
||||
Package for more details.
|
||||
|
||||
In the below table, if three IDs are listed, the first is the PCI Device
|
||||
ID, the second is the PCI Subsystem Vendor ID, and the third is the PCI
|
||||
Subsystem Device ID.
|
||||
|
||||
| Product Name | PCI ID |
|
||||
| ------------------------------------------------------- | -------------- |
|
||||
| NVIDIA TITAN RTX | 1E02 |
|
||||
| NVIDIA GeForce RTX 2080 Ti | 1E04 |
|
||||
| NVIDIA GeForce RTX 2080 Ti | 1E07 |
|
||||
| NVIDIA CMP 50HX | 1E09 |
|
||||
| Quadro RTX 6000 | 1E30 |
|
||||
| Quadro RTX 8000 | 1E30 1028 129E |
|
||||
| Quadro RTX 8000 | 1E30 103C 129E |
|
||||
| Quadro RTX 8000 | 1E30 10DE 129E |
|
||||
| Quadro RTX 6000 | 1E36 |
|
||||
| Quadro RTX 8000 | 1E78 10DE 13D8 |
|
||||
| Quadro RTX 6000 | 1E78 10DE 13D9 |
|
||||
| NVIDIA GeForce RTX 2080 SUPER | 1E81 |
|
||||
| NVIDIA GeForce RTX 2080 | 1E82 |
|
||||
| NVIDIA GeForce RTX 2070 SUPER | 1E84 |
|
||||
| NVIDIA GeForce RTX 2080 | 1E87 |
|
||||
| NVIDIA GeForce RTX 2060 | 1E89 |
|
||||
| NVIDIA GeForce RTX 2080 | 1E90 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1025 1375 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08A1 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08A2 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08EA |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08EB |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08EC |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08ED |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08EE |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 08EF |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 093B |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1028 093C |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 8572 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 8573 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 8602 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 8606 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 86C6 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 86C7 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 87A6 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 103C 87A7 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1043 131F |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1043 137F |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1043 141F |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1043 1751 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 1660 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 1661 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 1662 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 75A6 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 75A7 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 86A6 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1458 86A7 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1462 1274 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1462 1277 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 152D 1220 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1558 95E1 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1558 97E1 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1A58 2002 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1A58 2005 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1A58 2007 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1A58 3000 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1A58 3001 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1E90 1D05 1069 |
|
||||
| NVIDIA GeForce RTX 2070 Super | 1E91 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 103C 8607 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 103C 8736 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 103C 8738 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 103C 8772 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 103C 878A |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 103C 878B |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1043 1E61 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 1511 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 75B3 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 75B4 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 76B2 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 76B3 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 78A2 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 78A3 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 86B2 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1458 86B3 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1462 12AE |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1462 12B0 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1462 12C6 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 17AA 22C3 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 17AA 22C5 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1A58 2009 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1A58 200A |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 1A58 3002 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1E91 8086 3012 |
|
||||
| NVIDIA GeForce RTX 2080 Super | 1E93 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1025 1401 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1025 149C |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1028 09D2 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 8607 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 86C7 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 8736 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 8738 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 8772 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 87A6 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 103C 87A7 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 75B1 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 75B2 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 76B0 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 76B1 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 78A0 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 78A1 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 86B0 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1458 86B1 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1462 12AE |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1462 12B0 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1462 12B4 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1462 12C6 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1558 50D3 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1558 70D1 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 17AA 22C3 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 17AA 22C5 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1A58 2009 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1A58 200A |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1A58 3002 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1E93 1D05 1089 |
|
||||
| Quadro RTX 5000 | 1EB0 |
|
||||
| Quadro RTX 4000 | 1EB1 |
|
||||
| Quadro RTX 5000 | 1EB5 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1025 1375 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1025 1401 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1025 149C |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1028 09C3 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8736 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8738 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8772 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8780 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8782 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8783 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 103C 8785 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1043 1DD1 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1462 1274 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1462 12B0 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1462 12C6 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 17AA 22B8 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 17AA 22BA |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1A58 2005 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1A58 2007 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1A58 2008 |
|
||||
| Quadro RTX 5000 with Max-Q Design | 1EB5 1A58 200A |
|
||||
| Quadro RTX 4000 | 1EB6 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 1028 09C3 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8736 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8738 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8772 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8780 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8782 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8783 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 103C 8785 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 1462 1274 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 1462 1277 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 1462 12B0 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 1462 12C6 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 17AA 22B8 |
|
||||
| Quadro RTX 4000 with Max-Q Design | 1EB6 17AA 22BA |
|
||||
| Tesla T4 | 1EB8 10DE 12A2 |
|
||||
| NVIDIA GeForce RTX 2070 SUPER | 1EC2 |
|
||||
| NVIDIA GeForce RTX 2070 SUPER | 1EC7 |
|
||||
| NVIDIA GeForce RTX 2080 | 1ED0 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 1025 132D |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 1028 08ED |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 1028 08EE |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 1028 08EF |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 103C 8572 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 103C 8573 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 103C 8600 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 103C 8605 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 1043 138F |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 1043 15C1 |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 17AA 3FEE |
|
||||
| NVIDIA GeForce RTX 2080 with Max-Q Design | 1ED0 17AA 3FFE |
|
||||
| NVIDIA GeForce RTX 2070 Super | 1ED1 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 1025 1432 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 103C 8746 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 103C 878A |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 1043 165F |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 144D C192 |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 17AA 3FCE |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 17AA 3FCF |
|
||||
| NVIDIA GeForce RTX 2070 Super with Max-Q Design | 1ED1 17AA 3FD0 |
|
||||
| NVIDIA GeForce RTX 2080 Super | 1ED3 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 1025 1432 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 1028 09D1 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 103C 8746 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 103C 878A |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 1043 1D61 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 1043 1E51 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 1043 1F01 |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 17AA 3FCE |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 17AA 3FCF |
|
||||
| NVIDIA GeForce RTX 2080 Super with Max-Q Design | 1ED3 17AA 3FD0 |
|
||||
| Quadro RTX 5000 | 1EF5 |
|
||||
| NVIDIA GeForce RTX 2070 | 1F02 |
|
||||
| NVIDIA GeForce RTX 2060 | 1F03 |
|
||||
| NVIDIA GeForce RTX 2060 SUPER | 1F06 |
|
||||
| NVIDIA GeForce RTX 2070 | 1F07 |
|
||||
| NVIDIA GeForce RTX 2060 | 1F08 |
|
||||
| NVIDIA GeForce GTX 1650 | 1F0A |
|
||||
| NVIDIA CMP 40HX | 1F0B |
|
||||
| NVIDIA GeForce RTX 2070 | 1F10 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1025 132D |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1025 1342 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08A1 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08A2 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08EA |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08EB |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08EC |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08ED |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08EE |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 08EF |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 093B |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1028 093C |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 103C 8572 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 103C 8573 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 103C 8602 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 103C 8606 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1043 132F |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1043 136F |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1043 1881 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1043 1E6E |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 1658 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 1663 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 1664 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 75A4 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 75A5 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 86A4 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1458 86A5 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1462 1274 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1462 1277 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1558 95E1 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1558 97E1 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1A58 2002 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1A58 2005 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1A58 2007 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1A58 3000 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1A58 3001 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1D05 105E |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1D05 1070 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 1D05 2087 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F10 8086 2087 |
|
||||
| NVIDIA GeForce RTX 2060 | 1F11 |
|
||||
| NVIDIA GeForce RTX 2060 | 1F12 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 1028 098F |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 103C 8741 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 103C 8744 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 103C 878E |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 103C 880E |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 1043 1E11 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 1043 1F11 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 1462 12D9 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 17AA 3801 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 17AA 3802 |
|
||||
| NVIDIA GeForce RTX 2060 with Max-Q Design | 1F12 17AA 3803 |
|
||||
| NVIDIA GeForce RTX 2070 | 1F14 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1025 1401 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1025 1432 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1025 1442 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1025 1446 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1025 147D |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1028 09E2 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1028 09F3 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 8607 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 86C6 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 86C7 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 8736 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 8738 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 8746 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 8772 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 878A |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 878B |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 87A6 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 103C 87A7 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1043 174F |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 1512 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 75B5 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 75B6 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 76B4 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 76B5 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 78A4 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 78A5 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 86B4 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1458 86B5 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1462 12AE |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1462 12B0 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1462 12C6 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1558 50D3 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1558 70D1 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1A58 200C |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1A58 2011 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F14 1A58 3002 |
|
||||
| NVIDIA GeForce RTX 2060 | 1F15 |
|
||||
| Quadro RTX 3000 | 1F36 |
|
||||
| Quadro RTX 3000 with Max-Q Design | 1F36 1028 0990 |
|
||||
| Quadro RTX 3000 with Max-Q Design | 1F36 103C 8736 |
|
||||
| Quadro RTX 3000 with Max-Q Design | 1F36 103C 8738 |
|
||||
| Quadro RTX 3000 with Max-Q Design | 1F36 103C 8772 |
|
||||
| Quadro RTX 3000 with Max-Q Design | 1F36 1043 13CF |
|
||||
| Quadro RTX 3000 with Max-Q Design | 1F36 1414 0032 |
|
||||
| NVIDIA GeForce RTX 2060 SUPER | 1F42 |
|
||||
| NVIDIA GeForce RTX 2060 SUPER | 1F47 |
|
||||
| NVIDIA GeForce RTX 2070 | 1F50 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 1028 08ED |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 1028 08EE |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 1028 08EF |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 103C 8572 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 103C 8573 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 103C 8574 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 103C 8600 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 103C 8605 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 17AA 3FEE |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F50 17AA 3FFE |
|
||||
| NVIDIA GeForce RTX 2060 | 1F51 |
|
||||
| NVIDIA GeForce RTX 2070 | 1F54 |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F54 103C 878A |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F54 17AA 3FCE |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F54 17AA 3FCF |
|
||||
| NVIDIA GeForce RTX 2070 with Max-Q Design | 1F54 17AA 3FD0 |
|
||||
| NVIDIA GeForce RTX 2060 | 1F55 |
|
||||
| Quadro RTX 3000 | 1F76 |
|
||||
| Matrox D-Series D2450 | 1F76 102B 2800 |
|
||||
| Matrox D-Series D2480 | 1F76 102B 2900 |
|
||||
| NVIDIA GeForce GTX 1650 | 1F82 |
|
||||
| NVIDIA GeForce GTX 1630 | 1F83 |
|
||||
| NVIDIA GeForce GTX 1650 | 1F91 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 103C 863E |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 103C 86E7 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 103C 86E8 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1043 12CF |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1043 156F |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1414 0032 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 144D C822 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1462 127E |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1462 1281 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1462 1284 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1462 1285 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1462 129C |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 17AA 229F |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 17AA 3802 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 17AA 3806 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 17AA 3F1A |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F91 1A58 1001 |
|
||||
| NVIDIA GeForce GTX 1650 Ti | 1F95 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1025 1479 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1025 147A |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1025 147B |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1025 147C |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 103C 86E7 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 103C 86E8 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 103C 8815 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1043 1DFF |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1043 1E1F |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 144D C838 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1462 12BD |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1462 12C5 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1462 12D2 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 17AA 22C0 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 17AA 22C1 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 17AA 3837 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 17AA 3F95 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1A58 1003 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1A58 1006 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1A58 1007 |
|
||||
| NVIDIA GeForce GTX 1650 Ti with Max-Q Design | 1F95 1E83 3E30 |
|
||||
| NVIDIA GeForce GTX 1650 | 1F96 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F96 1462 1297 |
|
||||
| NVIDIA GeForce MX450 | 1F97 |
|
||||
| NVIDIA GeForce MX450 | 1F98 |
|
||||
| NVIDIA GeForce GTX 1650 | 1F99 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1025 1479 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1025 147A |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1025 147B |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1025 147C |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 103C 8815 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1043 13B2 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1043 1402 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1043 1902 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1462 12BD |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1462 12C5 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1462 12D2 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 17AA 22DA |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 17AA 3F93 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F99 1E83 3E30 |
|
||||
| NVIDIA GeForce MX450 | 1F9C |
|
||||
| NVIDIA GeForce GTX 1650 | 1F9D |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1043 128D |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1043 130D |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1043 149C |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1043 185C |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1043 189C |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1462 12F4 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1462 1302 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1462 131B |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1462 1326 |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1462 132A |
|
||||
| NVIDIA GeForce GTX 1650 with Max-Q Design | 1F9D 1462 132E |
|
||||
| NVIDIA GeForce MX550 | 1F9F |
|
||||
| NVIDIA GeForce MX550 | 1FA0 |
|
||||
| NVIDIA T1000 | 1FB0 1028 12DB |
|
||||
| NVIDIA T1000 | 1FB0 103C 12DB |
|
||||
| NVIDIA T1000 | 1FB0 103C 8A80 |
|
||||
| NVIDIA T1000 | 1FB0 10DE 12DB |
|
||||
| NVIDIA DGX Display | 1FB0 10DE 1485 |
|
||||
| NVIDIA T1000 | 1FB0 17AA 12DB |
|
||||
| NVIDIA T600 | 1FB1 1028 1488 |
|
||||
| NVIDIA T600 | 1FB1 103C 1488 |
|
||||
| NVIDIA T600 | 1FB1 103C 8A80 |
|
||||
| NVIDIA T600 | 1FB1 10DE 1488 |
|
||||
| NVIDIA T600 | 1FB1 17AA 1488 |
|
||||
| NVIDIA T400 | 1FB2 1028 1489 |
|
||||
| NVIDIA T400 | 1FB2 103C 1489 |
|
||||
| NVIDIA T400 | 1FB2 103C 8A80 |
|
||||
| NVIDIA T400 | 1FB2 10DE 1489 |
|
||||
| NVIDIA T400 | 1FB2 17AA 1489 |
|
||||
| NVIDIA T600 Laptop GPU | 1FB6 |
|
||||
| NVIDIA T550 Laptop GPU | 1FB7 |
|
||||
| Quadro T2000 | 1FB8 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 1028 097E |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8736 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8738 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8772 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8780 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8782 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8783 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 8785 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 103C 87F0 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 1462 1281 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 1462 12BD |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 17AA 22C0 |
|
||||
| Quadro T2000 with Max-Q Design | 1FB8 17AA 22C1 |
|
||||
| Quadro T1000 | 1FB9 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 1025 1479 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 1025 147A |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 1025 147B |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 1025 147C |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8736 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8738 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8772 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8780 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8782 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8783 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 8785 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 103C 87F0 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 1462 12BD |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 17AA 22C0 |
|
||||
| Quadro T1000 with Max-Q Design | 1FB9 17AA 22C1 |
|
||||
| NVIDIA T600 Laptop GPU | 1FBA |
|
||||
| NVIDIA T500 | 1FBB |
|
||||
| NVIDIA T1200 Laptop GPU | 1FBC |
|
||||
| NVIDIA GeForce GTX 1650 | 1FDD |
|
||||
| NVIDIA T1000 8GB | 1FF0 1028 1612 |
|
||||
| NVIDIA T1000 8GB | 1FF0 103C 1612 |
|
||||
| NVIDIA T1000 8GB | 1FF0 103C 8A80 |
|
||||
| NVIDIA T1000 8GB | 1FF0 10DE 1612 |
|
||||
| NVIDIA T1000 8GB | 1FF0 17AA 1612 |
|
||||
| NVIDIA T400 4GB | 1FF2 1028 1613 |
|
||||
| NVIDIA T400 4GB | 1FF2 103C 1613 |
|
||||
| NVIDIA T400E | 1FF2 103C 18FF |
|
||||
| NVIDIA T400 4GB | 1FF2 103C 8A80 |
|
||||
| NVIDIA T400 4GB | 1FF2 10DE 1613 |
|
||||
| NVIDIA T400E | 1FF2 10DE 18FF |
|
||||
| NVIDIA T400 4GB | 1FF2 17AA 1613 |
|
||||
| NVIDIA T400E | 1FF2 17AA 18FF |
|
||||
| Quadro T1000 | 1FF9 |
|
||||
| NVIDIA A100-SXM4-40GB | 20B0 |
|
||||
| NVIDIA A100-PG509-200 | 20B0 10DE 1450 |
|
||||
| NVIDIA A100-SXM4-80GB | 20B2 10DE 1463 |
|
||||
| NVIDIA A100-SXM4-80GB | 20B2 10DE 147F |
|
||||
| NVIDIA A100-SXM4-80GB | 20B2 10DE 1622 |
|
||||
| NVIDIA A100-SXM4-80GB | 20B2 10DE 1623 |
|
||||
| NVIDIA PG509-210 | 20B2 10DE 1625 |
|
||||
| NVIDIA A100-SXM-64GB | 20B3 10DE 14A7 |
|
||||
| NVIDIA A100-SXM-64GB | 20B3 10DE 14A8 |
|
||||
| NVIDIA A100 80GB PCIe | 20B5 10DE 1533 |
|
||||
| NVIDIA A100 80GB PCIe | 20B5 10DE 1642 |
|
||||
| NVIDIA PG506-232 | 20B6 10DE 1492 |
|
||||
| NVIDIA A30 | 20B7 10DE 1532 |
|
||||
| NVIDIA A30 | 20B7 10DE 1804 |
|
||||
| NVIDIA A30 | 20B7 10DE 1852 |
|
||||
| NVIDIA A800-SXM4-40GB | 20BD 10DE 17F4 |
|
||||
| NVIDIA A100-PCIE-40GB | 20F1 10DE 145F |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 179B |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 179C |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 179D |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 179E |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 179F |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 17A0 |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 17A1 |
|
||||
| NVIDIA A800-SXM4-80GB | 20F3 10DE 17A2 |
|
||||
| NVIDIA A800 80GB PCIe | 20F5 10DE 1799 |
|
||||
| NVIDIA A800 80GB PCIe LC | 20F5 10DE 179A |
|
||||
| NVIDIA A800 40GB Active | 20F6 1028 180A |
|
||||
| NVIDIA A800 40GB Active | 20F6 103C 180A |
|
||||
| NVIDIA A800 40GB Active | 20F6 10DE 180A |
|
||||
| NVIDIA A800 40GB Active | 20F6 17AA 180A |
|
||||
| NVIDIA AX800 | 20FD 10DE 17F8 |
|
||||
| NVIDIA GeForce GTX 1660 Ti | 2182 |
|
||||
| NVIDIA GeForce GTX 1660 | 2184 |
|
||||
| NVIDIA GeForce GTX 1650 SUPER | 2187 |
|
||||
| NVIDIA GeForce GTX 1650 | 2188 |
|
||||
| NVIDIA CMP 30HX | 2189 |
|
||||
| NVIDIA GeForce GTX 1660 Ti | 2191 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1028 0949 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 85FB |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 85FE |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 86D6 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 8741 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 8744 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 878D |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 87AF |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 103C 87B3 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1043 171F |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1043 17EF |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1043 18D1 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1414 0032 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1462 128A |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1462 128B |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1462 12C6 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1462 12CB |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1462 12CC |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 1462 12D9 |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 17AA 380C |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 17AA 381D |
|
||||
| NVIDIA GeForce GTX 1660 Ti with Max-Q Design | 2191 17AA 381E |
|
||||
| NVIDIA GeForce GTX 1650 Ti | 2192 |
|
||||
| NVIDIA GeForce GTX 1660 SUPER | 21C4 |
|
||||
| NVIDIA GeForce GTX 1660 Ti | 21D1 |
|
||||
| NVIDIA GeForce RTX 3090 Ti | 2203 |
|
||||
| NVIDIA GeForce RTX 3090 | 2204 |
|
||||
| NVIDIA GeForce RTX 3080 | 2206 |
|
||||
| NVIDIA GeForce RTX 3070 Ti | 2207 |
|
||||
| NVIDIA GeForce RTX 3080 Ti | 2208 |
|
||||
| NVIDIA GeForce RTX 3080 | 220A |
|
||||
| NVIDIA CMP 90HX | 220D |
|
||||
| NVIDIA GeForce RTX 3080 | 2216 |
|
||||
| NVIDIA RTX A6000 | 2230 1028 1459 |
|
||||
| NVIDIA RTX A6000 | 2230 103C 1459 |
|
||||
| NVIDIA RTX A6000 | 2230 10DE 1459 |
|
||||
| NVIDIA RTX A6000 | 2230 17AA 1459 |
|
||||
| NVIDIA RTX A5000 | 2231 1028 147E |
|
||||
| NVIDIA RTX A5000 | 2231 103C 147E |
|
||||
| NVIDIA RTX A5000 | 2231 10DE 147E |
|
||||
| NVIDIA RTX A5000 | 2231 17AA 147E |
|
||||
| NVIDIA RTX A4500 | 2232 1028 163C |
|
||||
| NVIDIA RTX A4500 | 2232 103C 163C |
|
||||
| NVIDIA RTX A4500 | 2232 10DE 163C |
|
||||
| NVIDIA RTX A4500 | 2232 17AA 163C |
|
||||
| NVIDIA RTX A5500 | 2233 1028 165A |
|
||||
| NVIDIA RTX A5500 | 2233 103C 165A |
|
||||
| NVIDIA RTX A5500 | 2233 10DE 165A |
|
||||
| NVIDIA RTX A5500 | 2233 17AA 165A |
|
||||
| NVIDIA A40 | 2235 10DE 145A |
|
||||
| NVIDIA A10 | 2236 10DE 1482 |
|
||||
| NVIDIA A10G | 2237 10DE 152F |
|
||||
| NVIDIA A10M | 2238 10DE 1677 |
|
||||
| NVIDIA H100 NVL | 2321 10DE 1839 |
|
||||
| NVIDIA H800 PCIe | 2322 10DE 17A4 |
|
||||
| NVIDIA H800 | 2324 10DE 17A6 |
|
||||
| NVIDIA H800 | 2324 10DE 17A8 |
|
||||
| NVIDIA H20 | 2329 10DE 198B |
|
||||
| NVIDIA H20 | 2329 10DE 198C |
|
||||
| NVIDIA H20-3e | 232C 10DE 2063 |
|
||||
| NVIDIA H100 80GB HBM3 | 2330 10DE 16C0 |
|
||||
| NVIDIA H100 80GB HBM3 | 2330 10DE 16C1 |
|
||||
| NVIDIA H100 PCIe | 2331 10DE 1626 |
|
||||
| NVIDIA H200 | 2335 10DE 18BE |
|
||||
| NVIDIA H200 | 2335 10DE 18BF |
|
||||
| NVIDIA H100 | 2339 10DE 17FC |
|
||||
| NVIDIA H800 NVL | 233A 10DE 183A |
|
||||
| NVIDIA H200 NVL | 233B 10DE 1996 |
|
||||
| NVIDIA GH200 120GB | 2342 10DE 16EB |
|
||||
| NVIDIA GH200 120GB | 2342 10DE 1805 |
|
||||
| NVIDIA GH200 480GB | 2342 10DE 1809 |
|
||||
| NVIDIA GH200 144G HBM3e | 2348 10DE 18D2 |
|
||||
| NVIDIA GeForce RTX 3060 Ti | 2414 |
|
||||
| NVIDIA GeForce RTX 3080 Ti Laptop GPU | 2420 |
|
||||
| NVIDIA RTX A5500 Laptop GPU | 2438 |
|
||||
| NVIDIA GeForce RTX 3080 Ti Laptop GPU | 2460 |
|
||||
| NVIDIA GeForce RTX 3070 Ti | 2482 |
|
||||
| NVIDIA GeForce RTX 3070 | 2484 |
|
||||
| NVIDIA GeForce RTX 3060 Ti | 2486 |
|
||||
| NVIDIA GeForce RTX 3060 | 2487 |
|
||||
| NVIDIA GeForce RTX 3070 | 2488 |
|
||||
| NVIDIA GeForce RTX 3060 Ti | 2489 |
|
||||
| NVIDIA CMP 70HX | 248A |
|
||||
| NVIDIA GeForce RTX 3080 Laptop GPU | 249C |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 249C 1D05 1194 |
|
||||
| NVIDIA GeForce RTX 3070 Laptop GPU | 249D |
|
||||
| NVIDIA GeForce RTX 3070 Ti Laptop GPU | 24A0 |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 24A0 1D05 1192 |
|
||||
| NVIDIA RTX A4000 | 24B0 1028 14AD |
|
||||
| NVIDIA RTX A4000 | 24B0 103C 14AD |
|
||||
| NVIDIA RTX A4000 | 24B0 10DE 14AD |
|
||||
| NVIDIA RTX A4000 | 24B0 17AA 14AD |
|
||||
| NVIDIA RTX A4000H | 24B1 10DE 1658 |
|
||||
| NVIDIA RTX A5000 Laptop GPU | 24B6 |
|
||||
| NVIDIA RTX A4000 Laptop GPU | 24B7 |
|
||||
| NVIDIA RTX A3000 Laptop GPU | 24B8 |
|
||||
| NVIDIA RTX A3000 12GB Laptop GPU | 24B9 |
|
||||
| NVIDIA RTX A4500 Laptop GPU | 24BA |
|
||||
| NVIDIA RTX A3000 12GB Laptop GPU | 24BB |
|
||||
| NVIDIA GeForce RTX 3060 | 24C7 |
|
||||
| NVIDIA GeForce RTX 3060 Ti | 24C9 |
|
||||
| NVIDIA GeForce RTX 3080 Laptop GPU | 24DC |
|
||||
| NVIDIA GeForce RTX 3070 Laptop GPU | 24DD |
|
||||
| NVIDIA GeForce RTX 3070 Ti Laptop GPU | 24E0 |
|
||||
| NVIDIA RTX A4500 Embedded GPU | 24FA |
|
||||
| NVIDIA GeForce RTX 3060 | 2503 |
|
||||
| NVIDIA GeForce RTX 3060 | 2504 |
|
||||
| NVIDIA GeForce RTX 3050 | 2507 |
|
||||
| NVIDIA GeForce RTX 3050 OEM | 2508 |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 2520 |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 2521 |
|
||||
| NVIDIA GeForce RTX 3050 Ti Laptop GPU | 2523 |
|
||||
| NVIDIA RTX A2000 | 2531 1028 151D |
|
||||
| NVIDIA RTX A2000 | 2531 103C 151D |
|
||||
| NVIDIA RTX A2000 | 2531 10DE 151D |
|
||||
| NVIDIA RTX A2000 | 2531 17AA 151D |
|
||||
| NVIDIA GeForce RTX 3060 | 2544 |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 2560 |
|
||||
| NVIDIA GeForce RTX 3050 Ti Laptop GPU | 2563 |
|
||||
| NVIDIA RTX A2000 12GB | 2571 1028 1611 |
|
||||
| NVIDIA RTX A2000 12GB | 2571 103C 1611 |
|
||||
| NVIDIA RTX A2000 12GB | 2571 10DE 1611 |
|
||||
| NVIDIA RTX A2000 12GB | 2571 17AA 1611 |
|
||||
| NVIDIA GeForce RTX 3050 | 2582 |
|
||||
| NVIDIA GeForce RTX 3050 | 2584 |
|
||||
| NVIDIA GeForce RTX 3050 Ti Laptop GPU | 25A0 |
|
||||
| NVIDIA GeForce RTX 3050Ti Laptop GPU | 25A0 103C 8928 |
|
||||
| NVIDIA GeForce RTX 3050Ti Laptop GPU | 25A0 103C 89F9 |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 25A0 1D05 1196 |
|
||||
| NVIDIA GeForce RTX 3050 Laptop GPU | 25A2 |
|
||||
| NVIDIA GeForce RTX 3050 Ti Laptop GPU | 25A2 1028 0BAF |
|
||||
| NVIDIA GeForce RTX 3060 Laptop GPU | 25A2 1D05 1195 |
|
||||
| NVIDIA GeForce RTX 3050 Laptop GPU | 25A5 |
|
||||
| NVIDIA GeForce MX570 | 25A6 |
|
||||
| NVIDIA GeForce RTX 2050 | 25A7 |
|
||||
| NVIDIA GeForce RTX 2050 | 25A9 |
|
||||
| NVIDIA GeForce MX570 A | 25AA |
|
||||
| NVIDIA GeForce RTX 3050 4GB Laptop GPU | 25AB |
|
||||
| NVIDIA GeForce RTX 3050 6GB Laptop GPU | 25AC |
|
||||
| NVIDIA GeForce RTX 2050 | 25AD |
|
||||
| NVIDIA RTX A1000 | 25B0 1028 1878 |
|
||||
| NVIDIA RTX A1000 | 25B0 103C 1878 |
|
||||
| NVIDIA RTX A1000 | 25B0 103C 8D96 |
|
||||
| NVIDIA RTX A1000 | 25B0 10DE 1878 |
|
||||
| NVIDIA RTX A1000 | 25B0 17AA 1878 |
|
||||
| NVIDIA RTX A400 | 25B2 1028 1879 |
|
||||
| NVIDIA RTX A400 | 25B2 103C 1879 |
|
||||
| NVIDIA RTX A400 | 25B2 103C 8D95 |
|
||||
| NVIDIA RTX A400 | 25B2 10DE 1879 |
|
||||
| NVIDIA RTX A400 | 25B2 17AA 1879 |
|
||||
| NVIDIA A16 | 25B6 10DE 14A9 |
|
||||
| NVIDIA A2 | 25B6 10DE 157E |
|
||||
| NVIDIA RTX A2000 Laptop GPU | 25B8 |
|
||||
| NVIDIA RTX A1000 Laptop GPU | 25B9 |
|
||||
| NVIDIA RTX A2000 8GB Laptop GPU | 25BA |
|
||||
| NVIDIA RTX A500 Laptop GPU | 25BB |
|
||||
| NVIDIA RTX A1000 6GB Laptop GPU | 25BC |
|
||||
| NVIDIA RTX A500 Laptop GPU | 25BD |
|
||||
| NVIDIA GeForce RTX 3050 Ti Laptop GPU | 25E0 |
|
||||
| NVIDIA GeForce RTX 3050 Laptop GPU | 25E2 |
|
||||
| NVIDIA GeForce RTX 3050 Laptop GPU | 25E5 |
|
||||
| NVIDIA GeForce RTX 3050 6GB Laptop GPU | 25EC |
|
||||
| NVIDIA GeForce RTX 2050 | 25ED |
|
||||
| NVIDIA RTX A1000 Embedded GPU | 25F9 |
|
||||
| NVIDIA RTX A2000 Embedded GPU | 25FA |
|
||||
| NVIDIA RTX A500 Embedded GPU | 25FB |
|
||||
| NVIDIA GeForce RTX 4090 | 2684 |
|
||||
| NVIDIA GeForce RTX 4090 D | 2685 |
|
||||
| NVIDIA GeForce RTX 4070 Ti SUPER | 2689 |
|
||||
| NVIDIA RTX 6000 Ada Generation | 26B1 1028 16A1 |
|
||||
| NVIDIA RTX 6000 Ada Generation | 26B1 103C 16A1 |
|
||||
| NVIDIA RTX 6000 Ada Generation | 26B1 10DE 16A1 |
|
||||
| NVIDIA RTX 6000 Ada Generation | 26B1 17AA 16A1 |
|
||||
| NVIDIA RTX 5000 Ada Generation | 26B2 1028 17FA |
|
||||
| NVIDIA RTX 5000 Ada Generation | 26B2 103C 17FA |
|
||||
| NVIDIA RTX 5000 Ada Generation | 26B2 10DE 17FA |
|
||||
| NVIDIA RTX 5000 Ada Generation | 26B2 17AA 17FA |
|
||||
| NVIDIA RTX 5880 Ada Generation | 26B3 1028 1934 |
|
||||
| NVIDIA RTX 5880 Ada Generation | 26B3 103C 1934 |
|
||||
| NVIDIA RTX 5880 Ada Generation | 26B3 10DE 1934 |
|
||||
| NVIDIA RTX 5880 Ada Generation | 26B3 17AA 1934 |
|
||||
| NVIDIA L40 | 26B5 10DE 169D |
|
||||
| NVIDIA L40 | 26B5 10DE 17DA |
|
||||
| NVIDIA L40S | 26B9 10DE 1851 |
|
||||
| NVIDIA L40S | 26B9 10DE 18CF |
|
||||
| NVIDIA L20 | 26BA 10DE 1957 |
|
||||
| NVIDIA L20 | 26BA 10DE 1990 |
|
||||
| NVIDIA GeForce RTX 4080 SUPER | 2702 |
|
||||
| NVIDIA GeForce RTX 4080 | 2704 |
|
||||
| NVIDIA GeForce RTX 4070 Ti SUPER | 2705 |
|
||||
| NVIDIA GeForce RTX 4070 | 2709 |
|
||||
| NVIDIA GeForce RTX 4090 Laptop GPU | 2717 |
|
||||
| NVIDIA RTX 5000 Ada Generation Laptop GPU | 2730 |
|
||||
| NVIDIA GeForce RTX 4090 Laptop GPU | 2757 |
|
||||
| NVIDIA RTX 5000 Ada Generation Embedded GPU | 2770 |
|
||||
| NVIDIA GeForce RTX 4070 Ti | 2782 |
|
||||
| NVIDIA GeForce RTX 4070 SUPER | 2783 |
|
||||
| NVIDIA GeForce RTX 4070 | 2786 |
|
||||
| NVIDIA GeForce RTX 4060 Ti | 2788 |
|
||||
| NVIDIA GeForce RTX 4080 Laptop GPU | 27A0 |
|
||||
| NVIDIA RTX 4000 SFF Ada Generation | 27B0 1028 16FA |
|
||||
| NVIDIA RTX 4000 SFF Ada Generation | 27B0 103C 16FA |
|
||||
| NVIDIA RTX 4000 SFF Ada Generation | 27B0 10DE 16FA |
|
||||
| NVIDIA RTX 4000 SFF Ada Generation | 27B0 17AA 16FA |
|
||||
| NVIDIA RTX 4500 Ada Generation | 27B1 1028 180C |
|
||||
| NVIDIA RTX 4500 Ada Generation | 27B1 103C 180C |
|
||||
| NVIDIA RTX 4500 Ada Generation | 27B1 10DE 180C |
|
||||
| NVIDIA RTX 4500 Ada Generation | 27B1 17AA 180C |
|
||||
| NVIDIA RTX 4000 Ada Generation | 27B2 1028 181B |
|
||||
| NVIDIA RTX 4000 Ada Generation | 27B2 103C 181B |
|
||||
| NVIDIA RTX 4000 Ada Generation | 27B2 10DE 181B |
|
||||
| NVIDIA RTX 4000 Ada Generation | 27B2 17AA 181B |
|
||||
| NVIDIA L2 | 27B6 10DE 1933 |
|
||||
| NVIDIA L4 | 27B8 10DE 16CA |
|
||||
| NVIDIA L4 | 27B8 10DE 16EE |
|
||||
| NVIDIA RTX 4000 Ada Generation Laptop GPU | 27BA |
|
||||
| NVIDIA RTX 3500 Ada Generation Laptop GPU | 27BB |
|
||||
| NVIDIA GeForce RTX 4080 Laptop GPU | 27E0 |
|
||||
| NVIDIA RTX 3500 Ada Generation Embedded GPU | 27FB |
|
||||
| NVIDIA GeForce RTX 4060 Ti | 2803 |
|
||||
| NVIDIA GeForce RTX 4060 Ti | 2805 |
|
||||
| NVIDIA GeForce RTX 4060 | 2808 |
|
||||
| NVIDIA GeForce RTX 4070 Laptop GPU | 2820 |
|
||||
| NVIDIA GeForce RTX 3050 A Laptop GPU | 2822 |
|
||||
| NVIDIA RTX 3000 Ada Generation Laptop GPU | 2838 |
|
||||
| NVIDIA GeForce RTX 4070 Laptop GPU | 2860 |
|
||||
| NVIDIA GeForce RTX 4060 | 2882 |
|
||||
| NVIDIA GeForce RTX 4060 Laptop GPU | 28A0 |
|
||||
| NVIDIA GeForce RTX 4050 Laptop GPU | 28A1 |
|
||||
| NVIDIA GeForce RTX 3050 A Laptop GPU | 28A3 |
|
||||
| NVIDIA RTX 2000 Ada Generation | 28B0 1028 1870 |
|
||||
| NVIDIA RTX 2000 Ada Generation | 28B0 103C 1870 |
|
||||
| NVIDIA RTX 2000E Ada Generation | 28B0 103C 1871 |
|
||||
| NVIDIA RTX 2000 Ada Generation | 28B0 10DE 1870 |
|
||||
| NVIDIA RTX 2000E Ada Generation | 28B0 10DE 1871 |
|
||||
| NVIDIA RTX 2000 Ada Generation | 28B0 17AA 1870 |
|
||||
| NVIDIA RTX 2000E Ada Generation | 28B0 17AA 1871 |
|
||||
| NVIDIA RTX 2000 Ada Generation Laptop GPU | 28B8 |
|
||||
| NVIDIA RTX 1000 Ada Generation Laptop GPU | 28B9 |
|
||||
| NVIDIA RTX 500 Ada Generation Laptop GPU | 28BA |
|
||||
| NVIDIA RTX 500 Ada Generation Laptop GPU | 28BB |
|
||||
| NVIDIA GeForce RTX 4060 Laptop GPU | 28E0 |
|
||||
| NVIDIA GeForce RTX 4050 Laptop GPU | 28E1 |
|
||||
| NVIDIA GeForce RTX 3050 A Laptop GPU | 28E3 |
|
||||
| NVIDIA RTX 2000 Ada Generation Embedded GPU | 28F8 |
|
||||
| NVIDIA B200 | 2901 10DE 1999 |
|
||||
| NVIDIA B200 | 2901 10DE 199B |
|
||||
| NVIDIA B200 | 2901 10DE 20DA |
|
||||
| NVIDIA GB200 | 2941 10DE 2046 |
|
||||
| NVIDIA GB200 | 2941 10DE 20CA |
|
||||
| NVIDIA GB200 | 2941 10DE 20D5 |
|
||||
| NVIDIA GB200 | 2941 10DE 21C9 |
|
||||
| NVIDIA GB200 | 2941 10DE 21CA |
|
||||
| NVIDIA GeForce RTX 5090 | 2B85 |
|
||||
| NVIDIA GeForce RTX 5090 D | 2B87 |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Workstation Edition | 2BB1 1028 204B |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Workstation Edition | 2BB1 103C 204B |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Workstation Edition | 2BB1 10DE 204B |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Workstation Edition | 2BB1 17AA 204B |
|
||||
| NVIDIA RTX PRO 5000 Blackwell | 2BB3 1028 204D |
|
||||
| NVIDIA RTX PRO 5000 Blackwell | 2BB3 103C 204D |
|
||||
| NVIDIA RTX PRO 5000 Blackwell | 2BB3 10DE 204D |
|
||||
| NVIDIA RTX PRO 5000 Blackwell | 2BB3 17AA 204D |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Max-Q Workstation Edition | 2BB4 1028 204C |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Max-Q Workstation Edition | 2BB4 103C 204C |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Max-Q Workstation Edition | 2BB4 10DE 204C |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Max-Q Workstation Edition | 2BB4 17AA 204C |
|
||||
| NVIDIA RTX PRO 6000 Blackwell Server Edition | 2BB5 10DE 204E |
|
||||
| NVIDIA GeForce RTX 5080 | 2C02 |
|
||||
| NVIDIA GeForce RTX 5070 Ti | 2C05 |
|
||||
| NVIDIA GeForce RTX 5090 Laptop GPU | 2C18 |
|
||||
| NVIDIA GeForce RTX 5080 Laptop GPU | 2C19 |
|
||||
| NVIDIA RTX PRO 5000 Blackwell Generation Laptop GPU | 2C38 |
|
||||
| NVIDIA RTX PRO 4000 Blackwell Generation Laptop GPU | 2C39 |
|
||||
| NVIDIA GeForce RTX 5090 Laptop GPU | 2C58 |
|
||||
| NVIDIA GeForce RTX 5080 Laptop GPU | 2C59 |
|
||||
| NVIDIA GeForce RTX 5060 Ti | 2D04 |
|
||||
| NVIDIA GeForce RTX 5060 | 2D05 |
|
||||
| NVIDIA GeForce RTX 5070 Laptop GPU | 2D18 |
|
||||
| NVIDIA GeForce RTX 5060 Laptop GPU | 2D19 |
|
||||
| NVIDIA RTX PRO 2000 Blackwell Generation Laptop GPU | 2D39 |
|
||||
| NVIDIA GeForce RTX 5070 Laptop GPU | 2D58 |
|
||||
| NVIDIA GeForce RTX 5060 Laptop GPU | 2D59 |
|
||||
| NVIDIA RTX PRO 1000 Blackwell Generation Laptop GPU | 2DB8 |
|
||||
| NVIDIA RTX PRO 500 Blackwell Generation Laptop GPU | 2DB9 |
|
||||
| NVIDIA GeForce RTX 5070 | 2F04 |
|
||||
| NVIDIA GeForce RTX 5070 Ti Laptop GPU | 2F18 |
|
||||
| NVIDIA RTX PRO 3000 Blackwell Generation Laptop GPU | 2F38 |
|
||||
| NVIDIA GeForce RTX 5070 Ti Laptop GPU | 2F58 |
|
||||
2665
commitFile.txt
2665
commitFile.txt
File diff suppressed because it is too large
Load Diff
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NV_CHARDEV_NUMBERS_H_
|
||||
#define _NV_CHARDEV_NUMBERS_H_
|
||||
|
||||
// NVIDIA's reserved major character device number (Linux).
|
||||
#define NV_MAJOR_DEVICE_NUMBER 195
|
||||
|
||||
// Minor numbers 0 to 247 reserved for regular devices
|
||||
#define NV_MINOR_DEVICE_NUMBER_REGULAR_MAX 247
|
||||
|
||||
// Minor numbers 248 to 253 currently unused
|
||||
|
||||
// Minor number 254 reserved for the modeset device (provided by NVKMS)
|
||||
#define NV_MINOR_DEVICE_NUMBER_MODESET_DEVICE 254
|
||||
|
||||
// Minor number 255 reserved for the control device
|
||||
#define NV_MINOR_DEVICE_NUMBER_CONTROL_DEVICE 255
|
||||
|
||||
#endif // _NV_CHARDEV_NUMBERS_H_
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//
|
||||
// This file holds GPU firmware related registry key definitions that are
|
||||
// shared between Windows and Unix
|
||||
//
|
||||
|
||||
#ifndef NV_FIRMWARE_REGISTRY_H
|
||||
#define NV_FIRMWARE_REGISTRY_H
|
||||
|
||||
//
|
||||
// Registry key that when enabled, will enable use of GPU firmware.
|
||||
//
|
||||
// Possible mode values:
|
||||
// 0 - Do not enable GPU firmware
|
||||
// 1 - Enable GPU firmware
|
||||
// 2 - (Default) Use the default enablement policy for GPU firmware
|
||||
//
|
||||
// Setting this to anything other than 2 will alter driver firmware-
|
||||
// enablement policies, possibly disabling GPU firmware where it would
|
||||
// have otherwise been enabled by default.
|
||||
//
|
||||
// Policy bits:
|
||||
//
|
||||
// POLICY_ALLOW_FALLBACK:
|
||||
// As the normal behavior is to fail GPU initialization if this registry
|
||||
// entry is set in such a way that results in an invalid configuration, if
|
||||
// instead the user would like the driver to automatically try to fallback
|
||||
// to initializing the failing GPU with firmware disabled, then this bit can
|
||||
// be set (ex: 0x11 means try to enable GPU firmware but fall back if needed).
|
||||
// Note that this can result in a mixed mode configuration (ex: GPU0 has
|
||||
// firmware enabled, but GPU1 does not).
|
||||
//
|
||||
#define NV_REG_STR_ENABLE_GPU_FIRMWARE "EnableGpuFirmware"
|
||||
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_MODE_MASK 0x0000000F
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_MODE_DISABLED 0x00000000
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_MODE_ENABLED 0x00000001
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_MODE_DEFAULT 0x00000002
|
||||
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_POLICY_MASK 0x000000F0
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_POLICY_ALLOW_FALLBACK 0x00000010
|
||||
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_DEFAULT_VALUE 0x00000012
|
||||
|
||||
//
|
||||
// Registry key that when enabled, will send GPU firmware logs
|
||||
// to the system log, when possible.
|
||||
//
|
||||
// Possible values:
|
||||
// 0 - Do not send GPU firmware logs to the system log
|
||||
// 1 - Enable sending of GPU firmware logs to the system log
|
||||
// 2 - (Default) Enable sending of GPU firmware logs to the system log for
|
||||
// the debug kernel driver build only
|
||||
//
|
||||
#define NV_REG_STR_ENABLE_GPU_FIRMWARE_LOGS "EnableGpuFirmwareLogs"
|
||||
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_LOGS_DISABLE 0x00000000
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_LOGS_ENABLE 0x00000001
|
||||
#define NV_REG_ENABLE_GPU_FIRMWARE_LOGS_ENABLE_ON_DEBUG 0x00000002
|
||||
|
||||
#endif // NV_FIRMWARE_REGISTRY_H
|
||||
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef NV_FIRMWARE_H
|
||||
#define NV_FIRMWARE_H
|
||||
|
||||
|
||||
|
||||
#include <nvtypes.h>
|
||||
#include <nvmisc.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NV_FIRMWARE_TYPE_GSP,
|
||||
NV_FIRMWARE_TYPE_GSP_LOG,
|
||||
#if defined(NV_VMWARE)
|
||||
NV_FIRMWARE_TYPE_BINDATA
|
||||
#endif
|
||||
} nv_firmware_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NV_FIRMWARE_CHIP_FAMILY_NULL = 0,
|
||||
NV_FIRMWARE_CHIP_FAMILY_TU10X = 1,
|
||||
NV_FIRMWARE_CHIP_FAMILY_TU11X = 2,
|
||||
NV_FIRMWARE_CHIP_FAMILY_GA100 = 3,
|
||||
NV_FIRMWARE_CHIP_FAMILY_GA10X = 4,
|
||||
NV_FIRMWARE_CHIP_FAMILY_AD10X = 5,
|
||||
NV_FIRMWARE_CHIP_FAMILY_GH100 = 6,
|
||||
NV_FIRMWARE_CHIP_FAMILY_GB10X = 8,
|
||||
NV_FIRMWARE_CHIP_FAMILY_GB10Y = 11,
|
||||
NV_FIRMWARE_CHIP_FAMILY_END,
|
||||
} nv_firmware_chip_family_t;
|
||||
|
||||
static inline const char *nv_firmware_chip_family_to_string(
|
||||
nv_firmware_chip_family_t fw_chip_family
|
||||
)
|
||||
{
|
||||
switch (fw_chip_family) {
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GB10X: return "gb10x";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GB10Y: return "gb10y";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GH100: return "gh100";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_AD10X: return "ad10x";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GA10X: return "ga10x";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GA100: return "ga100";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_TU11X: return "tu11x";
|
||||
case NV_FIRMWARE_CHIP_FAMILY_TU10X: return "tu10x";
|
||||
|
||||
case NV_FIRMWARE_CHIP_FAMILY_END: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_NULL:
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// The includer may optionally define
|
||||
// NV_FIRMWARE_FOR_NAME(name)
|
||||
// to return a platform-defined string for a given a gsp_* or gsp_log_* name.
|
||||
//
|
||||
// The function nv_firmware_for_chip_family will then be available.
|
||||
#if defined(NV_FIRMWARE_FOR_NAME)
|
||||
static inline const char *nv_firmware_for_chip_family(
|
||||
nv_firmware_type_t fw_type,
|
||||
nv_firmware_chip_family_t fw_chip_family
|
||||
)
|
||||
{
|
||||
if (fw_type == NV_FIRMWARE_TYPE_GSP)
|
||||
{
|
||||
switch (fw_chip_family)
|
||||
{
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GB10X: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GB10Y: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GH100: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_AD10X: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GA10X:
|
||||
return NV_FIRMWARE_FOR_NAME("gsp_ga10x");
|
||||
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GA100: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_TU11X: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_TU10X:
|
||||
return NV_FIRMWARE_FOR_NAME("gsp_tu10x");
|
||||
|
||||
case NV_FIRMWARE_CHIP_FAMILY_END: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_NULL:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else if (fw_type == NV_FIRMWARE_TYPE_GSP_LOG)
|
||||
{
|
||||
switch (fw_chip_family)
|
||||
{
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GB10X: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GB10Y: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GH100: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_AD10X: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GA10X:
|
||||
return NV_FIRMWARE_FOR_NAME("gsp_log_ga10x");
|
||||
|
||||
case NV_FIRMWARE_CHIP_FAMILY_GA100: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_TU11X: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_TU10X:
|
||||
return NV_FIRMWARE_FOR_NAME("gsp_log_tu10x");
|
||||
|
||||
case NV_FIRMWARE_CHIP_FAMILY_END: // fall through
|
||||
case NV_FIRMWARE_CHIP_FAMILY_NULL:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
#if defined(NV_VMWARE)
|
||||
else if (fw_type == NV_FIRMWARE_TYPE_BINDATA)
|
||||
{
|
||||
return NV_FIRMWARE_FOR_NAME("bindata_image");
|
||||
}
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
#endif // defined(NV_FIRMWARE_FOR_NAME)
|
||||
|
||||
// The includer may optionally define
|
||||
// NV_FIRMWARE_DECLARE_GSP(name)
|
||||
// which will then be invoked (at the top-level) for each
|
||||
// gsp_* (but not gsp_log_*)
|
||||
#if defined(NV_FIRMWARE_DECLARE_GSP)
|
||||
NV_FIRMWARE_DECLARE_GSP("gsp_ga10x")
|
||||
NV_FIRMWARE_DECLARE_GSP("gsp_tu10x")
|
||||
#endif // defined(NV_FIRMWARE_DECLARE_GSP)
|
||||
|
||||
#endif // NV_FIRMWARE_DECLARE_GSP
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_IOCTL_NUMA_H
|
||||
#define NV_IOCTL_NUMA_H
|
||||
|
||||
#include <nv-ioctl-numbers.h>
|
||||
|
||||
#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX)
|
||||
#include <linux/types.h>
|
||||
#elif defined (NV_KERNEL_INTERFACE_LAYER) && defined(NV_BSD)
|
||||
#include <sys/stdint.h>
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if !defined(__aligned)
|
||||
#define __aligned(n) __attribute__((aligned(n)))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define NV_ESC_NUMA_INFO (NV_IOCTL_BASE + 15)
|
||||
#define NV_ESC_SET_NUMA_STATUS (NV_IOCTL_BASE + 16)
|
||||
|
||||
#define NV_IOCTL_NUMA_INFO_MAX_OFFLINE_ADDRESSES 64
|
||||
typedef struct offline_addresses
|
||||
{
|
||||
uint64_t addresses[NV_IOCTL_NUMA_INFO_MAX_OFFLINE_ADDRESSES] __aligned(8);
|
||||
uint32_t numEntries;
|
||||
} nv_offline_addresses_t;
|
||||
|
||||
|
||||
/* per-device NUMA memory info as assigned by the system */
|
||||
typedef struct nv_ioctl_numa_info
|
||||
{
|
||||
int32_t nid;
|
||||
int32_t status;
|
||||
uint64_t memblock_size __aligned(8);
|
||||
uint64_t numa_mem_addr __aligned(8);
|
||||
uint64_t numa_mem_size __aligned(8);
|
||||
uint8_t use_auto_online;
|
||||
nv_offline_addresses_t offline_addresses __aligned(8);
|
||||
} nv_ioctl_numa_info_t;
|
||||
|
||||
/* set the status of the device NUMA memory */
|
||||
typedef struct nv_ioctl_set_numa_status
|
||||
{
|
||||
int32_t status;
|
||||
} nv_ioctl_set_numa_status_t;
|
||||
|
||||
#define NV_IOCTL_NUMA_STATUS_DISABLED 0
|
||||
#define NV_IOCTL_NUMA_STATUS_OFFLINE 1
|
||||
#define NV_IOCTL_NUMA_STATUS_ONLINE_IN_PROGRESS 2
|
||||
#define NV_IOCTL_NUMA_STATUS_ONLINE 3
|
||||
#define NV_IOCTL_NUMA_STATUS_ONLINE_FAILED 4
|
||||
#define NV_IOCTL_NUMA_STATUS_OFFLINE_IN_PROGRESS 5
|
||||
#define NV_IOCTL_NUMA_STATUS_OFFLINE_FAILED 6
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __NV_KTHREAD_QUEUE_OS_H__
|
||||
#define __NV_KTHREAD_QUEUE_OS_H__
|
||||
|
||||
#include <linux/types.h> // atomic_t
|
||||
#include <linux/list.h> // list
|
||||
#include <linux/sched.h> // task_struct
|
||||
#include <linux/numa.h> // NUMA_NO_NODE
|
||||
#include <linux/semaphore.h>
|
||||
|
||||
#include "conftest.h"
|
||||
|
||||
struct nv_kthread_q
|
||||
{
|
||||
struct list_head q_list_head;
|
||||
spinlock_t q_lock;
|
||||
|
||||
// This is a counting semaphore. It gets incremented and decremented
|
||||
// exactly once for each item that is added to the queue.
|
||||
struct semaphore q_sem;
|
||||
atomic_t main_loop_should_exit;
|
||||
|
||||
struct task_struct *q_kthread;
|
||||
|
||||
bool is_unload_flush_ongoing;
|
||||
};
|
||||
|
||||
struct nv_kthread_q_item
|
||||
{
|
||||
struct list_head q_list_node;
|
||||
nv_q_func_t function_to_run;
|
||||
void *function_args;
|
||||
};
|
||||
|
||||
|
||||
#ifndef NUMA_NO_NODE
|
||||
#define NUMA_NO_NODE (-1)
|
||||
#endif
|
||||
|
||||
#define NV_KTHREAD_NO_NODE NUMA_NO_NODE
|
||||
|
||||
#endif
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef __NV_MM_H__
|
||||
#define __NV_MM_H__
|
||||
|
||||
#include "conftest.h"
|
||||
|
||||
#if !defined(NV_VM_FAULT_T_IS_PRESENT)
|
||||
typedef int vm_fault_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* pin_user_pages()
|
||||
*
|
||||
* Presence of pin_user_pages() also implies the presence of unpin-user_page().
|
||||
* Both were added in the v5.6.
|
||||
*
|
||||
* pin_user_pages() was added by commit eddb1c228f79
|
||||
* ("mm/gup: introduce pin_user_pages*() and FOLL_PIN") in v5.6.
|
||||
*
|
||||
* Removed vmas parameter from pin_user_pages() by commit 4c630f307455
|
||||
* ("mm/gup: remove vmas parameter from pin_user_pages()") in v6.5.
|
||||
*/
|
||||
|
||||
#include <linux/mm.h>
|
||||
#include <linux/sched.h>
|
||||
|
||||
/*
|
||||
* FreeBSD's pin_user_pages's conftest breaks since pin_user_pages is an inline
|
||||
* function. Because it simply maps to get_user_pages, we can just replace
|
||||
* NV_PIN_USER_PAGES with NV_GET_USER_PAGES on FreeBSD
|
||||
*/
|
||||
#if defined(NV_PIN_USER_PAGES_PRESENT) && !defined(NV_BSD)
|
||||
#if defined(NV_PIN_USER_PAGES_HAS_ARGS_VMAS)
|
||||
#define NV_PIN_USER_PAGES(start, nr_pages, gup_flags, pages) \
|
||||
pin_user_pages(start, nr_pages, gup_flags, pages, NULL)
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES pin_user_pages
|
||||
#endif // NV_PIN_USER_PAGES_HAS_ARGS_VMAS
|
||||
#define NV_UNPIN_USER_PAGE unpin_user_page
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES NV_GET_USER_PAGES
|
||||
#define NV_UNPIN_USER_PAGE put_page
|
||||
#endif // NV_PIN_USER_PAGES_PRESENT
|
||||
|
||||
/*
|
||||
* get_user_pages()
|
||||
*
|
||||
* Removed vmas parameter from get_user_pages() by commit 54d020692b34
|
||||
* ("mm/gup: remove unused vmas parameter from get_user_pages()") in v6.5.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(NV_GET_USER_PAGES_HAS_VMAS_ARG)
|
||||
#define NV_GET_USER_PAGES get_user_pages
|
||||
#else
|
||||
#define NV_GET_USER_PAGES(start, nr_pages, flags, pages) \
|
||||
get_user_pages(start, nr_pages, flags, pages, NULL)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* pin_user_pages_remote()
|
||||
*
|
||||
* pin_user_pages_remote() was added by commit eddb1c228f79
|
||||
* ("mm/gup: introduce pin_user_pages*() and FOLL_PIN") in v5.6.
|
||||
*
|
||||
* pin_user_pages_remote() removed 'tsk' parameter by commit
|
||||
* 64019a2e467a ("mm/gup: remove task_struct pointer for all gup code")
|
||||
* in v5.9.
|
||||
*
|
||||
* Removed unused vmas parameter from pin_user_pages_remote() by commit
|
||||
* 0b295316b3a9 ("mm/gup: remove unused vmas parameter from
|
||||
* pin_user_pages_remote()") in v6.5.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(NV_PIN_USER_PAGES_REMOTE_PRESENT)
|
||||
#if defined(NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS)
|
||||
#define NV_PIN_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, locked) \
|
||||
pin_user_pages_remote(NULL, mm, start, nr_pages, flags, pages, NULL, locked)
|
||||
#elif defined(NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_VMAS)
|
||||
#define NV_PIN_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, locked) \
|
||||
pin_user_pages_remote(mm, start, nr_pages, flags, pages, NULL, locked)
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES_REMOTE pin_user_pages_remote
|
||||
#endif // NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES_REMOTE NV_GET_USER_PAGES_REMOTE
|
||||
#endif // NV_PIN_USER_PAGES_REMOTE_PRESENT
|
||||
|
||||
/*
|
||||
* Note that get_user_pages_remote() requires the caller to hold a reference on
|
||||
* the mm_struct.
|
||||
* This will always be true when using current and current->mm. If the kernel passes
|
||||
* the driver a vma via driver callback, the kernel holds a reference on vma->vm_mm
|
||||
* over that callback.
|
||||
*
|
||||
* get_user_pages_remote() removed 'tsk' parameter by
|
||||
* commit 64019a2e467a ("mm/gup: remove task_struct pointer for
|
||||
* all gup code") in v5.9.
|
||||
*
|
||||
* Removed vmas parameter from get_user_pages_remote() by commit ca5e863233e8
|
||||
* ("mm/gup: remove vmas parameter from get_user_pages_remote()") in v6.5.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS)
|
||||
#define NV_GET_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, locked) \
|
||||
get_user_pages_remote(NULL, mm, start, nr_pages, flags, pages, NULL, locked)
|
||||
#elif defined(NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK)
|
||||
#define NV_GET_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, locked) \
|
||||
get_user_pages_remote(mm, start, nr_pages, flags, pages, NULL, locked)
|
||||
|
||||
#else
|
||||
#define NV_GET_USER_PAGES_REMOTE get_user_pages_remote
|
||||
#endif
|
||||
|
||||
static inline void nv_mmap_read_lock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_read_lock(mm);
|
||||
#else
|
||||
down_read(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_read_unlock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_read_unlock(mm);
|
||||
#else
|
||||
up_read(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_write_lock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_write_lock(mm);
|
||||
#else
|
||||
down_write(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_write_unlock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_write_unlock(mm);
|
||||
#else
|
||||
up_write(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int nv_mm_rwsem_is_locked(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
return rwsem_is_locked(&mm->mmap_lock);
|
||||
#else
|
||||
return rwsem_is_locked(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline struct rw_semaphore *nv_mmap_get_lock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
return &mm->mmap_lock;
|
||||
#else
|
||||
return &mm->mmap_sem;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_vm_flags_set(struct vm_area_struct *vma, vm_flags_t flags)
|
||||
{
|
||||
#if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS)
|
||||
vm_flags_set(vma, flags);
|
||||
#else
|
||||
vma->vm_flags |= flags;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_vm_flags_clear(struct vm_area_struct *vma, vm_flags_t flags)
|
||||
{
|
||||
#if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS)
|
||||
vm_flags_clear(vma, flags);
|
||||
#else
|
||||
vma->vm_flags &= ~flags;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // __NV_MM_H__
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2015 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __NV_COMMON_UTILS_H__
|
||||
#define __NV_COMMON_UTILS_H__
|
||||
|
||||
#include "nvtypes.h"
|
||||
#include "nvmisc.h"
|
||||
|
||||
#if !defined(TRUE)
|
||||
#define TRUE NV_TRUE
|
||||
#endif
|
||||
|
||||
#if !defined(FALSE)
|
||||
#define FALSE NV_FALSE
|
||||
#endif
|
||||
|
||||
#define NV_IS_UNSIGNED(x) ((__typeof__(x))-1 > 0)
|
||||
|
||||
/* Get the length of a statically-sized array. */
|
||||
#define ARRAY_LEN(_arr) (sizeof(_arr) / sizeof(_arr[0]))
|
||||
|
||||
#define NV_INVALID_HEAD 0xFFFFFFFF
|
||||
|
||||
#define NV_INVALID_CONNECTOR_PHYSICAL_INFORMATION (~0)
|
||||
|
||||
#if !defined(NV_MIN)
|
||||
# define NV_MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#define NV_MIN3(a,b,c) NV_MIN(NV_MIN(a, b), c)
|
||||
#define NV_MIN4(a,b,c,d) NV_MIN3(NV_MIN(a,b),c,d)
|
||||
|
||||
#if !defined(NV_MAX)
|
||||
# define NV_MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#define NV_MAX3(a,b,c) NV_MAX(NV_MAX(a, b), c)
|
||||
#define NV_MAX4(a,b,c,d) NV_MAX3(NV_MAX(a,b),c,d)
|
||||
|
||||
static inline int NV_LIMIT_VAL_TO_MIN_MAX(int val, int min, int max)
|
||||
{
|
||||
if (val < min) {
|
||||
return min;
|
||||
}
|
||||
if (val > max) {
|
||||
return max;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
#define NV_ROUNDUP_DIV(x,y) ((x) / (y) + (((x) % (y)) ? 1 : 0))
|
||||
|
||||
/*
|
||||
* Macros used for computing palette entries:
|
||||
*
|
||||
* NV_UNDER_REPLICATE(val, source_size, result_size) expands a value
|
||||
* of source_size bits into a value of target_size bits by shifting
|
||||
* the source value into the high bits and replicating the high bits
|
||||
* of the value into the low bits of the result.
|
||||
*
|
||||
* PALETTE_DEPTH_SHIFT(val, w) maps a colormap entry for a component
|
||||
* that has w bits to an appropriate entry in a LUT of 256 entries.
|
||||
*/
|
||||
static inline unsigned int NV_UNDER_REPLICATE(unsigned short val,
|
||||
int source_size,
|
||||
int result_size)
|
||||
{
|
||||
return (val << (result_size - source_size)) |
|
||||
(val >> ((source_size << 1) - result_size));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned short PALETTE_DEPTH_SHIFT(unsigned short val, int depth)
|
||||
{
|
||||
return NV_UNDER_REPLICATE(val, depth, 8);
|
||||
}
|
||||
|
||||
/*
|
||||
* Use __builtin_ffs where it is supported, or provide an equivalent
|
||||
* implementation for platforms like riscv where it is not.
|
||||
*/
|
||||
#if defined(__GNUC__) && !NVCPU_IS_RISCV64
|
||||
static inline int nv_ffs(int x)
|
||||
{
|
||||
return __builtin_ffs(x);
|
||||
}
|
||||
#else
|
||||
static inline int nv_ffs(int x)
|
||||
{
|
||||
if (x == 0)
|
||||
return 0;
|
||||
|
||||
LOWESTBITIDX_32(x);
|
||||
|
||||
return 1 + x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NV_COMMON_UTILS_H__ */
|
||||
@@ -1,370 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2010-2014 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
* This header file defines the types NVDpyId and NVDpyIdList, as well
|
||||
* as inline functions to manipulate these types. NVDpyId and
|
||||
* NVDpyIdList should be treated as opaque by includers of this header
|
||||
* file.
|
||||
*/
|
||||
|
||||
#ifndef __NV_DPY_ID_H__
|
||||
#define __NV_DPY_ID_H__
|
||||
|
||||
#include "nvtypes.h"
|
||||
#include "nvmisc.h"
|
||||
#include "nv_common_utils.h"
|
||||
#include <nvlimits.h> /* NV_MAX_SUBDEVICES */
|
||||
|
||||
typedef struct {
|
||||
NvU32 opaqueDpyId;
|
||||
} NVDpyId;
|
||||
|
||||
typedef struct {
|
||||
NvU32 opaqueDpyIdList;
|
||||
} NVDpyIdList;
|
||||
|
||||
#define NV_DPY_ID_MAX_SUBDEVICES NV_MAX_SUBDEVICES
|
||||
#define NV_DPY_ID_MAX_DPYS_IN_LIST 32
|
||||
|
||||
/*
|
||||
* For use in combination with nvDpyIdToPrintFormat(); e.g.,
|
||||
*
|
||||
* printf("dpy id: " NV_DPY_ID_PRINT_FORMAT "\n",
|
||||
* nvDpyIdToPrintFormat(dpyId));
|
||||
*
|
||||
* The includer should not make assumptions about the return type of
|
||||
* nvDpyIdToPrintFormat().
|
||||
*/
|
||||
#define NV_DPY_ID_PRINT_FORMAT "0x%08x"
|
||||
|
||||
/* functions to return an invalid DpyId and empty DpyIdList */
|
||||
|
||||
static inline NVDpyId nvInvalidDpyId(void)
|
||||
{
|
||||
NVDpyId dpyId = { 0 };
|
||||
return dpyId;
|
||||
}
|
||||
|
||||
static inline NVDpyIdList nvEmptyDpyIdList(void)
|
||||
{
|
||||
NVDpyIdList dpyIdList = { 0 };
|
||||
return dpyIdList;
|
||||
}
|
||||
|
||||
static inline NVDpyIdList nvAllDpyIdList(void)
|
||||
{
|
||||
NVDpyIdList dpyIdList = { ~0U };
|
||||
return dpyIdList;
|
||||
}
|
||||
|
||||
static inline void
|
||||
nvEmptyDpyIdListSubDeviceArray(NVDpyIdList dpyIdList[NV_DPY_ID_MAX_SUBDEVICES])
|
||||
{
|
||||
int dispIndex;
|
||||
for (dispIndex = 0; dispIndex < NV_DPY_ID_MAX_SUBDEVICES; dispIndex++) {
|
||||
dpyIdList[dispIndex] = nvEmptyDpyIdList();
|
||||
}
|
||||
}
|
||||
|
||||
/* set operations on DpyIds and DpyIdLists: Add, Subtract, Intersect, Xor */
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvAddDpyIdToDpyIdList(NVDpyId dpyId, NVDpyIdList dpyIdList)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdList.opaqueDpyIdList |
|
||||
dpyId.opaqueDpyId;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
/* Passing an invalid display ID makes this function return an empty list. */
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvAddDpyIdToEmptyDpyIdList(NVDpyId dpyId)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyId.opaqueDpyId;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvAddDpyIdListToDpyIdList(NVDpyIdList dpyIdListA,
|
||||
NVDpyIdList dpyIdListB)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdListB.opaqueDpyIdList |
|
||||
dpyIdListA.opaqueDpyIdList;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
/* Returns: dpyIdList - dpyId */
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvDpyIdListMinusDpyId(NVDpyIdList dpyIdList, NVDpyId dpyId)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdList.opaqueDpyIdList &
|
||||
(~dpyId.opaqueDpyId);
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
/* Returns: dpyIdListA - dpyIdListB */
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvDpyIdListMinusDpyIdList(NVDpyIdList dpyIdListA,
|
||||
NVDpyIdList dpyIdListB)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdListA.opaqueDpyIdList &
|
||||
(~dpyIdListB.opaqueDpyIdList);
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvIntersectDpyIdAndDpyIdList(NVDpyId dpyId, NVDpyIdList dpyIdList)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdList.opaqueDpyIdList &
|
||||
dpyId.opaqueDpyId;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvIntersectDpyIdListAndDpyIdList(NVDpyIdList dpyIdListA,
|
||||
NVDpyIdList dpyIdListB)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdListA.opaqueDpyIdList &
|
||||
dpyIdListB.opaqueDpyIdList;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvXorDpyIdAndDpyIdList(NVDpyId dpyId, NVDpyIdList dpyIdList)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdList.opaqueDpyIdList ^
|
||||
dpyId.opaqueDpyId;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyIdList nvXorDpyIdListAndDpyIdList(NVDpyIdList dpyIdListA,
|
||||
NVDpyIdList dpyIdListB)
|
||||
{
|
||||
NVDpyIdList tmpDpyIdList;
|
||||
tmpDpyIdList.opaqueDpyIdList = dpyIdListA.opaqueDpyIdList ^
|
||||
dpyIdListB.opaqueDpyIdList;
|
||||
return tmpDpyIdList;
|
||||
}
|
||||
|
||||
|
||||
/* boolean checks */
|
||||
|
||||
static inline NvBool nvDpyIdIsInDpyIdList(NVDpyId dpyId,
|
||||
NVDpyIdList dpyIdList)
|
||||
{
|
||||
return !!(dpyIdList.opaqueDpyIdList & dpyId.opaqueDpyId);
|
||||
}
|
||||
|
||||
static inline NvBool nvDpyIdIsInvalid(NVDpyId dpyId)
|
||||
{
|
||||
return (dpyId.opaqueDpyId == 0);
|
||||
}
|
||||
|
||||
static inline NvBool nvDpyIdListIsEmpty(NVDpyIdList dpyIdList)
|
||||
{
|
||||
return (dpyIdList.opaqueDpyIdList == 0);
|
||||
}
|
||||
|
||||
static inline NvBool
|
||||
nvDpyIdListSubDeviceArrayIsEmpty(NVDpyIdList
|
||||
dpyIdList[NV_DPY_ID_MAX_SUBDEVICES])
|
||||
{
|
||||
int dispIndex;
|
||||
for (dispIndex = 0; dispIndex < NV_DPY_ID_MAX_SUBDEVICES; dispIndex++) {
|
||||
if (!nvDpyIdListIsEmpty(dpyIdList[dispIndex])) {
|
||||
return NV_FALSE;
|
||||
}
|
||||
}
|
||||
return NV_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static inline NvBool nvDpyIdsAreEqual(NVDpyId dpyIdA, NVDpyId dpyIdB)
|
||||
{
|
||||
return (dpyIdA.opaqueDpyId == dpyIdB.opaqueDpyId);
|
||||
}
|
||||
|
||||
static inline NvBool nvDpyIdListsAreEqual(NVDpyIdList dpyIdListA,
|
||||
NVDpyIdList dpyIdListB)
|
||||
{
|
||||
return (dpyIdListA.opaqueDpyIdList == dpyIdListB.opaqueDpyIdList);
|
||||
}
|
||||
|
||||
static inline NvBool nvDpyIdListIsASubSetofDpyIdList(NVDpyIdList dpyIdListA,
|
||||
NVDpyIdList dpyIdListB)
|
||||
{
|
||||
NVDpyIdList intersectedDpyIdList =
|
||||
nvIntersectDpyIdListAndDpyIdList(dpyIdListA, dpyIdListB);
|
||||
|
||||
return nvDpyIdListsAreEqual(intersectedDpyIdList, dpyIdListA);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* retrieve the individual dpyIds from dpyIdList; if dpyId is invalid,
|
||||
* start at the beginning of the list; otherwise, start at the dpyId
|
||||
* after the specified dpyId
|
||||
*/
|
||||
|
||||
static inline __attribute__ ((warn_unused_result))
|
||||
NVDpyId nvNextDpyIdInDpyIdListUnsorted(NVDpyId dpyId, NVDpyIdList dpyIdList)
|
||||
{
|
||||
if (nvDpyIdIsInvalid(dpyId)) {
|
||||
dpyId.opaqueDpyId = 1;
|
||||
} else {
|
||||
dpyId.opaqueDpyId <<= 1;
|
||||
}
|
||||
|
||||
while (dpyId.opaqueDpyId) {
|
||||
|
||||
if (nvDpyIdIsInDpyIdList(dpyId, dpyIdList)) {
|
||||
return dpyId;
|
||||
}
|
||||
|
||||
dpyId.opaqueDpyId <<= 1;
|
||||
}
|
||||
|
||||
/* no dpyIds left in dpyIdlist; return the invalid dpyId */
|
||||
|
||||
return nvInvalidDpyId();
|
||||
}
|
||||
|
||||
#define FOR_ALL_DPY_IDS(_dpyId, _dpyIdList) \
|
||||
for ((_dpyId) = nvNextDpyIdInDpyIdListUnsorted(nvInvalidDpyId(), \
|
||||
(_dpyIdList)); \
|
||||
!nvDpyIdIsInvalid(_dpyId); \
|
||||
(_dpyId) = nvNextDpyIdInDpyIdListUnsorted((_dpyId), \
|
||||
(_dpyIdList)))
|
||||
|
||||
/* report how many dpyIds are in the dpyIdList */
|
||||
|
||||
static inline int nvCountDpyIdsInDpyIdList(NVDpyIdList dpyIdList)
|
||||
{
|
||||
return nvPopCount32(dpyIdList.opaqueDpyIdList);
|
||||
}
|
||||
|
||||
static inline int
|
||||
nvCountDpyIdsInDpyIdListSubDeviceArray(NVDpyIdList
|
||||
dpyIdList[NV_DPY_ID_MAX_SUBDEVICES])
|
||||
{
|
||||
int dispIndex, n = 0;
|
||||
|
||||
for (dispIndex = 0; dispIndex < NV_DPY_ID_MAX_SUBDEVICES; dispIndex++) {
|
||||
n += nvCountDpyIdsInDpyIdList(dpyIdList[dispIndex]);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/* convert between dpyId/dpyIdList and NV-CONTROL values */
|
||||
|
||||
static inline int nvDpyIdToNvControlVal(NVDpyId dpyId)
|
||||
{
|
||||
return (int) dpyId.opaqueDpyId;
|
||||
}
|
||||
|
||||
static inline int nvDpyIdListToNvControlVal(NVDpyIdList dpyIdList)
|
||||
{
|
||||
return (int) dpyIdList.opaqueDpyIdList;
|
||||
}
|
||||
|
||||
static inline NVDpyId nvNvControlValToDpyId(int val)
|
||||
{
|
||||
NVDpyId dpyId;
|
||||
dpyId.opaqueDpyId = (val == 0) ? 0 : 1 << (nv_ffs(val)-1);
|
||||
return dpyId;
|
||||
}
|
||||
|
||||
static inline NVDpyIdList nvNvControlValToDpyIdList(int val)
|
||||
{
|
||||
NVDpyIdList dpyIdList;
|
||||
dpyIdList.opaqueDpyIdList = val;
|
||||
return dpyIdList;
|
||||
}
|
||||
|
||||
|
||||
/* convert between dpyId and NvU32 */
|
||||
|
||||
static inline NVDpyId nvNvU32ToDpyId(NvU32 val)
|
||||
{
|
||||
NVDpyId dpyId;
|
||||
dpyId.opaqueDpyId = (val == 0) ? 0 : 1 << (nv_ffs(val)-1);
|
||||
return dpyId;
|
||||
}
|
||||
|
||||
static inline NVDpyIdList nvNvU32ToDpyIdList(NvU32 val)
|
||||
{
|
||||
NVDpyIdList dpyIdList;
|
||||
dpyIdList.opaqueDpyIdList = val;
|
||||
return dpyIdList;
|
||||
}
|
||||
|
||||
static inline NvU32 nvDpyIdToNvU32(NVDpyId dpyId)
|
||||
{
|
||||
return dpyId.opaqueDpyId;
|
||||
}
|
||||
|
||||
static inline NvU32 nvDpyIdListToNvU32(NVDpyIdList dpyIdList)
|
||||
{
|
||||
return dpyIdList.opaqueDpyIdList;
|
||||
}
|
||||
|
||||
/* Return the bit position of dpyId: a number in the range [0..31]. */
|
||||
static inline NvU32 nvDpyIdToIndex(NVDpyId dpyId)
|
||||
{
|
||||
return nv_ffs(dpyId.opaqueDpyId) - 1;
|
||||
}
|
||||
|
||||
/* Return a display ID that is not in the list passed in. */
|
||||
|
||||
static inline NVDpyId nvNewDpyId(NVDpyIdList excludeList)
|
||||
{
|
||||
NVDpyId dpyId;
|
||||
if (~excludeList.opaqueDpyIdList == 0) {
|
||||
return nvInvalidDpyId();
|
||||
}
|
||||
dpyId.opaqueDpyId =
|
||||
1U << (nv_ffs(~excludeList.opaqueDpyIdList) - 1);
|
||||
return dpyId;
|
||||
}
|
||||
|
||||
/* See comment for NV_DPY_ID_PRINT_FORMAT. */
|
||||
static inline NvU32 nvDpyIdToPrintFormat(NVDpyId dpyId)
|
||||
{
|
||||
return nvDpyIdToNvU32(dpyId);
|
||||
}
|
||||
|
||||
/* Prevent usage of opaque values. */
|
||||
#define opaqueDpyId __ERROR_ACCESS_ME_VIA_NV_DPY_ID_H
|
||||
#define opaqueDpyIdList __ERROR_ACCESS_ME_VIA_NV_DPY_ID_H
|
||||
|
||||
#endif /* __NV_DPY_ID_H__ */
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//
|
||||
// This file provides common types for the UVM kernel driver, UVM user layer,
|
||||
// and RM's UVM interface.
|
||||
//
|
||||
|
||||
#ifndef _NV_UVM_USER_TYPES_H_
|
||||
#define _NV_UVM_USER_TYPES_H_
|
||||
|
||||
#include "nvtypes.h"
|
||||
|
||||
//
|
||||
// Default Page Size if left "0" because in RM BIG page size is default & there
|
||||
// are multiple BIG page sizes in RM. These defines are used as flags to "0"
|
||||
// should be OK when user is not sure which pagesize allocation it wants
|
||||
//
|
||||
#define UVM_PAGE_SIZE_DEFAULT 0x0ULL
|
||||
#define UVM_PAGE_SIZE_4K 0x1000ULL
|
||||
#define UVM_PAGE_SIZE_64K 0x10000ULL
|
||||
#define UVM_PAGE_SIZE_128K 0x20000ULL
|
||||
#define UVM_PAGE_SIZE_2M 0x200000ULL
|
||||
#define UVM_PAGE_SIZE_512M 0x20000000ULL
|
||||
#define UVM_PAGE_SIZE_256G 0x4000000000ULL
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UVM_VIRT_MODE_NONE = 0, // Baremetal or passthrough virtualization
|
||||
UVM_VIRT_MODE_LEGACY = 1, // Virtualization without SRIOV support
|
||||
UVM_VIRT_MODE_SRIOV_HEAVY = 2, // Virtualization with SRIOV Heavy configured
|
||||
UVM_VIRT_MODE_SRIOV_STANDARD = 3, // Virtualization with SRIOV Standard configured
|
||||
UVM_VIRT_MODE_COUNT = 4,
|
||||
} UVM_VIRT_MODE;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// UVM GPU mapping types
|
||||
//
|
||||
// These types indicate the kinds of accesses allowed from a given GPU at the
|
||||
// specified virtual address range. There are 3 basic kinds of accesses: read,
|
||||
// write and atomics. Each type indicates what kinds of accesses are allowed.
|
||||
// Accesses of any disallowed kind are fatal. The "Default" type specifies that
|
||||
// the UVM driver should decide on the types of accesses allowed.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef enum
|
||||
{
|
||||
UvmGpuMappingTypeDefault = 0,
|
||||
UvmGpuMappingTypeReadWriteAtomic = 1,
|
||||
UvmGpuMappingTypeReadWrite = 2,
|
||||
UvmGpuMappingTypeReadOnly = 3,
|
||||
UvmGpuMappingTypeCount = 4
|
||||
} UvmGpuMappingType;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// UVM GPU caching types
|
||||
//
|
||||
// These types indicate the cacheability of the specified virtual address range
|
||||
// from a given GPU. The "Default" type specifies that the UVM driver should
|
||||
// set caching on or off as required to follow the UVM coherence model. The
|
||||
// "ForceUncached" and "ForceCached" types will always turn caching off or on
|
||||
// respectively. These two types override the cacheability specified by the UVM
|
||||
// coherence model.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef enum
|
||||
{
|
||||
UvmGpuCachingTypeDefault = 0,
|
||||
UvmGpuCachingTypeForceUncached = 1,
|
||||
UvmGpuCachingTypeForceCached = 2,
|
||||
UvmGpuCachingTypeCount = 3
|
||||
} UvmGpuCachingType;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// UVM GPU format types
|
||||
//
|
||||
// These types indicate the memory format of the specified virtual address
|
||||
// range for a given GPU. The "Default" type specifies that the UVM driver will
|
||||
// detect the format based on the allocation and is mutually inclusive with
|
||||
// UvmGpuFormatElementBitsDefault.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef enum {
|
||||
UvmGpuFormatTypeDefault = 0,
|
||||
UvmGpuFormatTypeBlockLinear = 1,
|
||||
UvmGpuFormatTypeCount = 2
|
||||
} UvmGpuFormatType;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// UVM GPU Element bits types
|
||||
//
|
||||
// These types indicate the element size of the specified virtual address range
|
||||
// for a given GPU. The "Default" type specifies that the UVM driver will
|
||||
// detect the element size based on the allocation and is mutually inclusive
|
||||
// with UvmGpuFormatTypeDefault. The element size is specified in bits:
|
||||
// UvmGpuFormatElementBits8 uses the 8-bits format.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef enum {
|
||||
UvmGpuFormatElementBitsDefault = 0,
|
||||
UvmGpuFormatElementBits8 = 1,
|
||||
UvmGpuFormatElementBits16 = 2,
|
||||
// Cuda does not support 24-bit width
|
||||
UvmGpuFormatElementBits32 = 4,
|
||||
UvmGpuFormatElementBits64 = 5,
|
||||
UvmGpuFormatElementBits128 = 6,
|
||||
UvmGpuFormatElementBitsCount = 7
|
||||
} UvmGpuFormatElementBits;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// UVM GPU Compression types
|
||||
//
|
||||
// These types indicate the compression type of the specified virtual address
|
||||
// range for a given GPU. The "Default" type specifies that the UVM driver will
|
||||
// detect the compression attributes based on the allocation. Any type other
|
||||
// than the default will override the compression behavior of the physical
|
||||
// allocation. UvmGpuCompressionTypeEnabledNoPlc will disable PLC but enables
|
||||
// generic compression. UvmGpuCompressionTypeEnabledNoPlc type is only supported
|
||||
// on Turing plus GPUs. Since UvmGpuCompressionTypeEnabledNoPlc type enables
|
||||
// generic compression, it can only be used when the compression attribute of
|
||||
// the underlying physical allocation is enabled.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef enum {
|
||||
UvmGpuCompressionTypeDefault = 0,
|
||||
UvmGpuCompressionTypeEnabledNoPlc = 1,
|
||||
UvmGpuCompressionTypeCount = 2
|
||||
} UvmGpuCompressionType;
|
||||
|
||||
//
|
||||
// Mirrored in PMA (PMA_STATS)
|
||||
//
|
||||
typedef struct UvmPmaStatistics_tag
|
||||
{
|
||||
volatile NvU64 numPages2m; // PMA-wide 2MB pages count across all regions
|
||||
volatile NvU64 numFreePages64k; // PMA-wide free 64KB page count across all regions
|
||||
volatile NvU64 numFreePages2m; // PMA-wide free 2MB pages count across all regions
|
||||
volatile NvU64 numPages2mProtected; // PMA-wide 2MB pages count in protected memory
|
||||
volatile NvU64 numFreePages64kProtected; // PMA-wide free 64KB page count in protected memory
|
||||
volatile NvU64 numFreePages2mProtected; // PMA-wide free 2MB pages count in protected memory
|
||||
} UvmPmaStatistics;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UVM_ACCESS_COUNTER_GRANULARITY_64K = 1,
|
||||
UVM_ACCESS_COUNTER_GRANULARITY_2M = 2,
|
||||
UVM_ACCESS_COUNTER_GRANULARITY_16M = 3,
|
||||
UVM_ACCESS_COUNTER_GRANULARITY_16G = 4,
|
||||
} UVM_ACCESS_COUNTER_GRANULARITY;
|
||||
|
||||
#endif // _NV_UVM_USER_TYPES_H_
|
||||
@@ -1,279 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 1999-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Os interface definitions needed by os-interface.c
|
||||
*/
|
||||
|
||||
#ifndef OS_INTERFACE_H
|
||||
#define OS_INTERFACE_H
|
||||
|
||||
/******************* Operating System Interface Routines *******************\
|
||||
* *
|
||||
* Operating system wrapper functions used to abstract the OS. *
|
||||
* *
|
||||
\***************************************************************************/
|
||||
|
||||
#include <nvtypes.h>
|
||||
#include <nvstatus.h>
|
||||
#include "nv_stdarg.h"
|
||||
#include <nv-kernel-interface-api.h>
|
||||
#include <os/nv_memory_type.h>
|
||||
#include <os/nv_memory_area.h>
|
||||
#include <nv-caps.h>
|
||||
|
||||
#include "rs_access.h"
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NvU32 os_major_version;
|
||||
NvU32 os_minor_version;
|
||||
NvU32 os_build_number;
|
||||
const char * os_build_version_str;
|
||||
const char * os_build_date_plus_str;
|
||||
}os_version_info;
|
||||
|
||||
/* Each OS defines its own version of this opaque type */
|
||||
struct os_work_queue;
|
||||
|
||||
/* Each OS defines its own version of this opaque type */
|
||||
typedef struct os_wait_queue os_wait_queue;
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------------
|
||||
*
|
||||
* Function prototypes for OS interface.
|
||||
*
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
NV_STATUS NV_API_CALL os_alloc_mem (void **, NvU64);
|
||||
void NV_API_CALL os_free_mem (void *);
|
||||
NV_STATUS NV_API_CALL os_get_system_time (NvU32 *, NvU32 *);
|
||||
NvU64 NV_API_CALL os_get_monotonic_time_ns (void);
|
||||
NvU64 NV_API_CALL os_get_monotonic_time_ns_hr (void);
|
||||
NvU64 NV_API_CALL os_get_monotonic_tick_resolution_ns (void);
|
||||
NV_STATUS NV_API_CALL os_delay (NvU32);
|
||||
NV_STATUS NV_API_CALL os_delay_us (NvU32);
|
||||
NvU64 NV_API_CALL os_get_cpu_frequency (void);
|
||||
NvU32 NV_API_CALL os_get_current_process (void);
|
||||
void NV_API_CALL os_get_current_process_name (char *, NvU32);
|
||||
NV_STATUS NV_API_CALL os_get_current_thread (NvU64 *);
|
||||
char* NV_API_CALL os_string_copy (char *, const char *);
|
||||
NvU32 NV_API_CALL os_string_length (const char *);
|
||||
NvU32 NV_API_CALL os_strtoul (const char *, char **, NvU32);
|
||||
NvS32 NV_API_CALL os_string_compare (const char *, const char *);
|
||||
NvS32 NV_API_CALL os_snprintf (char *, NvU32, const char *, ...);
|
||||
NvS32 NV_API_CALL os_vsnprintf (char *, NvU32, const char *, va_list);
|
||||
void NV_API_CALL os_log_error (const char *, va_list);
|
||||
void* NV_API_CALL os_mem_copy (void *, const void *, NvU32);
|
||||
NV_STATUS NV_API_CALL os_memcpy_from_user (void *, const void *, NvU32);
|
||||
NV_STATUS NV_API_CALL os_memcpy_to_user (void *, const void *, NvU32);
|
||||
void* NV_API_CALL os_mem_set (void *, NvU8, NvU32);
|
||||
NvS32 NV_API_CALL os_mem_cmp (const NvU8 *, const NvU8 *, NvU32);
|
||||
void* NV_API_CALL os_pci_init_handle (NvU32, NvU8, NvU8, NvU8, NvU16 *, NvU16 *);
|
||||
NV_STATUS NV_API_CALL os_pci_read_byte (void *, NvU32, NvU8 *);
|
||||
NV_STATUS NV_API_CALL os_pci_read_word (void *, NvU32, NvU16 *);
|
||||
NV_STATUS NV_API_CALL os_pci_read_dword (void *, NvU32, NvU32 *);
|
||||
NV_STATUS NV_API_CALL os_pci_write_byte (void *, NvU32, NvU8);
|
||||
NV_STATUS NV_API_CALL os_pci_write_word (void *, NvU32, NvU16);
|
||||
NV_STATUS NV_API_CALL os_pci_write_dword (void *, NvU32, NvU32);
|
||||
NvBool NV_API_CALL os_pci_remove_supported (void);
|
||||
void NV_API_CALL os_pci_remove (void *);
|
||||
void* NV_API_CALL os_map_kernel_space (NvU64, NvU64, NvU32);
|
||||
void NV_API_CALL os_unmap_kernel_space (void *, NvU64);
|
||||
#if defined(NV_VMWARE)
|
||||
void* NV_API_CALL os_map_user_space (MemoryArea *, NvU32, NvU32, void **);
|
||||
void NV_API_CALL os_unmap_user_space (void *, NvU64, void *);
|
||||
#endif
|
||||
NV_STATUS NV_API_CALL os_flush_cpu_cache_all (void);
|
||||
NV_STATUS NV_API_CALL os_flush_user_cache (void);
|
||||
void NV_API_CALL os_flush_cpu_write_combine_buffer(void);
|
||||
NvU8 NV_API_CALL os_io_read_byte (NvU32);
|
||||
NvU16 NV_API_CALL os_io_read_word (NvU32);
|
||||
NvU32 NV_API_CALL os_io_read_dword (NvU32);
|
||||
void NV_API_CALL os_io_write_byte (NvU32, NvU8);
|
||||
void NV_API_CALL os_io_write_word (NvU32, NvU16);
|
||||
void NV_API_CALL os_io_write_dword (NvU32, NvU32);
|
||||
NvBool NV_API_CALL os_is_administrator (void);
|
||||
NvBool NV_API_CALL os_check_access (RsAccessRight accessRight);
|
||||
void NV_API_CALL os_dbg_init (void);
|
||||
void NV_API_CALL os_dbg_breakpoint (void);
|
||||
void NV_API_CALL os_dbg_set_level (NvU32);
|
||||
NvU32 NV_API_CALL os_get_cpu_count (void);
|
||||
NvU32 NV_API_CALL os_get_cpu_number (void);
|
||||
void NV_API_CALL os_disable_console_access (void);
|
||||
void NV_API_CALL os_enable_console_access (void);
|
||||
NV_STATUS NV_API_CALL os_registry_init (void);
|
||||
NvU64 NV_API_CALL os_get_max_user_va (void);
|
||||
NV_STATUS NV_API_CALL os_schedule (void);
|
||||
NV_STATUS NV_API_CALL os_alloc_spinlock (void **);
|
||||
void NV_API_CALL os_free_spinlock (void *);
|
||||
NvU64 NV_API_CALL os_acquire_spinlock (void *);
|
||||
void NV_API_CALL os_release_spinlock (void *, NvU64);
|
||||
NV_STATUS NV_API_CALL os_queue_work_item (struct os_work_queue *, void *);
|
||||
NV_STATUS NV_API_CALL os_flush_work_queue (struct os_work_queue *, NvBool);
|
||||
NvBool NV_API_CALL os_is_queue_flush_ongoing (struct os_work_queue *);
|
||||
NV_STATUS NV_API_CALL os_alloc_mutex (void **);
|
||||
void NV_API_CALL os_free_mutex (void *);
|
||||
NV_STATUS NV_API_CALL os_acquire_mutex (void *);
|
||||
NV_STATUS NV_API_CALL os_cond_acquire_mutex (void *);
|
||||
void NV_API_CALL os_release_mutex (void *);
|
||||
void* NV_API_CALL os_alloc_semaphore (NvU32);
|
||||
void NV_API_CALL os_free_semaphore (void *);
|
||||
NV_STATUS NV_API_CALL os_acquire_semaphore (void *);
|
||||
NV_STATUS NV_API_CALL os_cond_acquire_semaphore (void *);
|
||||
NV_STATUS NV_API_CALL os_release_semaphore (void *);
|
||||
void* NV_API_CALL os_alloc_rwlock (void);
|
||||
void NV_API_CALL os_free_rwlock (void *);
|
||||
NV_STATUS NV_API_CALL os_acquire_rwlock_read (void *);
|
||||
NV_STATUS NV_API_CALL os_acquire_rwlock_write (void *);
|
||||
NV_STATUS NV_API_CALL os_cond_acquire_rwlock_read (void *);
|
||||
NV_STATUS NV_API_CALL os_cond_acquire_rwlock_write (void *);
|
||||
void NV_API_CALL os_release_rwlock_read (void *);
|
||||
void NV_API_CALL os_release_rwlock_write (void *);
|
||||
NvBool NV_API_CALL os_semaphore_may_sleep (void);
|
||||
NV_STATUS NV_API_CALL os_get_version_info (os_version_info*);
|
||||
NV_STATUS NV_API_CALL os_get_is_openrm (NvBool *);
|
||||
NvBool NV_API_CALL os_is_isr (void);
|
||||
NvBool NV_API_CALL os_pat_supported (void);
|
||||
void NV_API_CALL os_dump_stack (void);
|
||||
NvBool NV_API_CALL os_is_efi_enabled (void);
|
||||
NvBool NV_API_CALL os_is_xen_dom0 (void);
|
||||
NvBool NV_API_CALL os_is_vgx_hyper (void);
|
||||
NV_STATUS NV_API_CALL os_inject_vgx_msi (NvU16, NvU64, NvU32);
|
||||
NvBool NV_API_CALL os_is_grid_supported (void);
|
||||
NvU32 NV_API_CALL os_get_grid_csp_support (void);
|
||||
void NV_API_CALL os_bug_check (NvU32, const char *);
|
||||
NV_STATUS NV_API_CALL os_lock_user_pages (void *, NvU64, void **, NvU32);
|
||||
NV_STATUS NV_API_CALL os_lookup_user_io_memory (void *, NvU64, NvU64 **);
|
||||
NV_STATUS NV_API_CALL os_unlock_user_pages (NvU64, void *, NvU32);
|
||||
NV_STATUS NV_API_CALL os_match_mmap_offset (void *, NvU64, NvU64 *);
|
||||
NV_STATUS NV_API_CALL os_get_euid (NvU32 *);
|
||||
NV_STATUS NV_API_CALL os_get_smbios_header (NvU64 *pSmbsAddr);
|
||||
NV_STATUS NV_API_CALL os_get_acpi_rsdp_from_uefi (NvU32 *);
|
||||
void NV_API_CALL os_add_record_for_crashLog (void *, NvU32);
|
||||
void NV_API_CALL os_delete_record_for_crashLog (void *);
|
||||
NV_STATUS NV_API_CALL os_call_vgpu_vfio (void *, NvU32);
|
||||
NV_STATUS NV_API_CALL os_device_vm_present (void);
|
||||
NV_STATUS NV_API_CALL os_numa_memblock_size (NvU64 *);
|
||||
NV_STATUS NV_API_CALL os_alloc_pages_node (NvS32, NvU32, NvU32, NvU64 *);
|
||||
NV_STATUS NV_API_CALL os_get_page (NvU64 address);
|
||||
NV_STATUS NV_API_CALL os_put_page (NvU64 address);
|
||||
NvU32 NV_API_CALL os_get_page_refcount (NvU64 address);
|
||||
NvU32 NV_API_CALL os_count_tail_pages (NvU64 address);
|
||||
void NV_API_CALL os_free_pages_phys (NvU64, NvU32);
|
||||
NV_STATUS NV_API_CALL os_open_temporary_file (void **);
|
||||
void NV_API_CALL os_close_file (void *);
|
||||
NV_STATUS NV_API_CALL os_write_file (void *, NvU8 *, NvU64, NvU64);
|
||||
NV_STATUS NV_API_CALL os_read_file (void *, NvU8 *, NvU64, NvU64);
|
||||
NV_STATUS NV_API_CALL os_open_readonly_file (const char *, void **);
|
||||
NV_STATUS NV_API_CALL os_open_and_read_file (const char *, NvU8 *, NvU64);
|
||||
NvBool NV_API_CALL os_is_nvswitch_present (void);
|
||||
NV_STATUS NV_API_CALL os_get_random_bytes (NvU8 *, NvU16);
|
||||
NV_STATUS NV_API_CALL os_alloc_wait_queue (os_wait_queue **);
|
||||
void NV_API_CALL os_free_wait_queue (os_wait_queue *);
|
||||
void NV_API_CALL os_wait_uninterruptible (os_wait_queue *);
|
||||
void NV_API_CALL os_wait_interruptible (os_wait_queue *);
|
||||
void NV_API_CALL os_wake_up (os_wait_queue *);
|
||||
nv_cap_t* NV_API_CALL os_nv_cap_init (const char *);
|
||||
nv_cap_t* NV_API_CALL os_nv_cap_create_dir_entry (nv_cap_t *, const char *, int);
|
||||
nv_cap_t* NV_API_CALL os_nv_cap_create_file_entry (nv_cap_t *, const char *, int);
|
||||
void NV_API_CALL os_nv_cap_destroy_entry (nv_cap_t *);
|
||||
int NV_API_CALL os_nv_cap_validate_and_dup_fd (const nv_cap_t *, int);
|
||||
void NV_API_CALL os_nv_cap_close_fd (int);
|
||||
NvS32 NV_API_CALL os_imex_channel_get (NvU64);
|
||||
NvS32 NV_API_CALL os_imex_channel_count (void);
|
||||
NV_STATUS NV_API_CALL os_tegra_igpu_perf_boost (void *, NvBool, NvU32);
|
||||
|
||||
NV_STATUS NV_API_CALL os_get_tegra_platform (NvU32 *);
|
||||
enum os_pci_req_atomics_type {
|
||||
OS_INTF_PCIE_REQ_ATOMICS_32BIT,
|
||||
OS_INTF_PCIE_REQ_ATOMICS_64BIT,
|
||||
OS_INTF_PCIE_REQ_ATOMICS_128BIT
|
||||
};
|
||||
NV_STATUS NV_API_CALL os_enable_pci_req_atomics (void *, enum os_pci_req_atomics_type);
|
||||
void NV_API_CALL os_pci_trigger_flr(void *handle);
|
||||
NV_STATUS NV_API_CALL os_get_numa_node_memory_usage (NvS32, NvU64 *, NvU64 *);
|
||||
NV_STATUS NV_API_CALL os_numa_add_gpu_memory (void *, NvU64, NvU64, NvU32 *);
|
||||
NV_STATUS NV_API_CALL os_numa_remove_gpu_memory (void *, NvU64, NvU64, NvU32);
|
||||
NV_STATUS NV_API_CALL os_offline_page_at_address(NvU64 address);
|
||||
void* NV_API_CALL os_get_pid_info(void);
|
||||
void NV_API_CALL os_put_pid_info(void *pid_info);
|
||||
NV_STATUS NV_API_CALL os_find_ns_pid(void *pid_info, NvU32 *ns_pid);
|
||||
NvBool NV_API_CALL os_is_init_ns(void);
|
||||
NV_STATUS NV_API_CALL os_iommu_sva_bind(void *arg, void **handle, NvU32 *pasid);
|
||||
void NV_API_CALL os_iommu_sva_unbind(void *handle);
|
||||
|
||||
extern NvU64 os_page_size;
|
||||
extern NvU64 os_max_page_size;
|
||||
extern NvU64 os_page_mask;
|
||||
extern NvU8 os_page_shift;
|
||||
extern NvBool os_cc_enabled;
|
||||
extern NvBool os_cc_sev_snp_enabled;
|
||||
extern NvBool os_cc_sme_enabled;
|
||||
extern NvBool os_cc_snp_vtom_enabled;
|
||||
extern NvBool os_cc_tdx_enabled;
|
||||
extern NvBool os_dma_buf_enabled;
|
||||
extern NvBool os_imex_channel_is_supported;
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------------
|
||||
*
|
||||
* Debug macros.
|
||||
*
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define NV_DBG_INFO 0x0
|
||||
#define NV_DBG_SETUP 0x1
|
||||
#define NV_DBG_USERERRORS 0x2
|
||||
#define NV_DBG_WARNINGS 0x3
|
||||
#define NV_DBG_ERRORS 0x4
|
||||
|
||||
|
||||
void NV_API_CALL out_string(const char *str);
|
||||
int NV_API_CALL nv_printf(NvU32 debuglevel, const char *printf_format, ...);
|
||||
|
||||
#define NV_DEV_PRINTF(debuglevel, nv, format, ... ) \
|
||||
nv_printf(debuglevel, "NVRM: GPU " NV_PCI_DEV_FMT ": " format, NV_PCI_DEV_FMT_ARGS(nv), ## __VA_ARGS__)
|
||||
|
||||
#define NV_DEV_PRINTF_STATUS(debuglevel, nv, status, format, ... ) \
|
||||
nv_printf(debuglevel, "NVRM: GPU " NV_PCI_DEV_FMT ": " format " (0x%x)\n", NV_PCI_DEV_FMT_ARGS(nv), ## __VA_ARGS__, status)
|
||||
|
||||
/*
|
||||
* Fields for os_lock_user_pages flags parameter
|
||||
*/
|
||||
#define NV_LOCK_USER_PAGES_FLAGS_WRITE 0:0
|
||||
#define NV_LOCK_USER_PAGES_FLAGS_WRITE_NO 0x00000000
|
||||
#define NV_LOCK_USER_PAGES_FLAGS_WRITE_YES 0x00000001
|
||||
|
||||
// NV OS Tegra platform type defines
|
||||
#define NV_OS_TEGRA_PLATFORM_SIM 0
|
||||
#define NV_OS_TEGRA_PLATFORM_FPGA 1
|
||||
#define NV_OS_TEGRA_PLATFORM_SILICON 2
|
||||
|
||||
#endif /* OS_INTERFACE_H */
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef NV_MEMORY_AREA_H
|
||||
#define NV_MEMORY_AREA_H
|
||||
|
||||
typedef struct MemoryRange
|
||||
{
|
||||
NvU64 start;
|
||||
NvU64 size;
|
||||
} MemoryRange;
|
||||
|
||||
typedef struct MemoryArea
|
||||
{
|
||||
MemoryRange *pRanges;
|
||||
NvU64 numRanges;
|
||||
} MemoryArea;
|
||||
|
||||
static inline NvU64 memareaSize(MemoryArea memArea)
|
||||
{
|
||||
NvU64 size = 0;
|
||||
NvU64 idx = 0;
|
||||
for (idx = 0; idx < memArea.numRanges; idx++)
|
||||
{
|
||||
size += memArea.pRanges[idx].size;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static inline MemoryRange
|
||||
mrangeMake
|
||||
(
|
||||
NvU64 start,
|
||||
NvU64 size
|
||||
)
|
||||
{
|
||||
MemoryRange range;
|
||||
range.start = start;
|
||||
range.size = size;
|
||||
return range;
|
||||
}
|
||||
|
||||
static inline NvU64
|
||||
mrangeLimit
|
||||
(
|
||||
MemoryRange a
|
||||
)
|
||||
{
|
||||
return a.start + a.size;
|
||||
}
|
||||
|
||||
static inline NvBool
|
||||
mrangeIntersects
|
||||
(
|
||||
MemoryRange a,
|
||||
MemoryRange b
|
||||
)
|
||||
{
|
||||
return ((a.start >= b.start) && (a.start < mrangeLimit(b))) ||
|
||||
((b.start >= a.start) && (b.start < mrangeLimit(a)));
|
||||
}
|
||||
|
||||
static inline NvBool
|
||||
mrangeContains
|
||||
(
|
||||
MemoryRange outer,
|
||||
MemoryRange inner
|
||||
)
|
||||
{
|
||||
return (inner.start >= outer.start) && (mrangeLimit(inner) <= mrangeLimit(outer));
|
||||
}
|
||||
|
||||
static inline MemoryRange
|
||||
mrangeOffset
|
||||
(
|
||||
MemoryRange range,
|
||||
NvU64 amt
|
||||
)
|
||||
{
|
||||
range.start += amt;
|
||||
return range;
|
||||
}
|
||||
|
||||
#endif /* NV_MEMORY_AREA_H */
|
||||
@@ -1,276 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <nvtypes.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable:4324)
|
||||
#endif
|
||||
|
||||
//
|
||||
// This file was generated with FINN, an NVIDIA coding tool.
|
||||
// Source file: rs_access.finn
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
#include "nvtypes.h"
|
||||
#include "nvmisc.h"
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* Access right definitions */
|
||||
/****************************************************************************/
|
||||
|
||||
//
|
||||
// The meaning of each access right is documented in
|
||||
// resman/docs/rmapi/resource_server/rm_capabilities.adoc
|
||||
//
|
||||
// RS_ACCESS_COUNT is the number of access rights that have been defined
|
||||
// and are in use. All integers in the range [0, RS_ACCESS_COUNT) should
|
||||
// represent valid access rights.
|
||||
//
|
||||
// When adding a new access right, don't forget to update
|
||||
// 1) The descriptions in the resman/docs/rmapi/resource_server/rm_capabilities.adoc
|
||||
// 2) RS_ACCESS_COUNT, defined below
|
||||
// 3) The declaration of g_rsAccessMetadata in rs_access_rights.c
|
||||
// 4) The list of access rights in drivers/common/chip-config/Chipcontrols.pm
|
||||
// 5) Any relevant access right callbacks
|
||||
//
|
||||
|
||||
#define RS_ACCESS_DUP_OBJECT 0U
|
||||
#define RS_ACCESS_NICE 1U
|
||||
#define RS_ACCESS_DEBUG 2U
|
||||
#define RS_ACCESS_PERFMON 3U
|
||||
#define RS_ACCESS_COUNT 4U
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* Access right data structures */
|
||||
/****************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief A type that can be used to represent any access right.
|
||||
*/
|
||||
typedef NvU16 RsAccessRight;
|
||||
|
||||
/*!
|
||||
* @brief An internal type used to represent one limb in an access right mask.
|
||||
*/
|
||||
typedef NvU32 RsAccessLimb;
|
||||
#define SDK_RS_ACCESS_LIMB_BITS 32
|
||||
|
||||
/*!
|
||||
* @brief The number of limbs in the RS_ACCESS_MASK struct.
|
||||
*/
|
||||
#define SDK_RS_ACCESS_MAX_LIMBS 1
|
||||
|
||||
/*!
|
||||
* @brief The maximum number of possible access rights supported by the
|
||||
* current data structure definition.
|
||||
*
|
||||
* You probably want RS_ACCESS_COUNT instead, which is the number of actual
|
||||
* access rights defined.
|
||||
*/
|
||||
#define SDK_RS_ACCESS_MAX_COUNT (0x20) /* finn: Evaluated from "(SDK_RS_ACCESS_LIMB_BITS * SDK_RS_ACCESS_MAX_LIMBS)" */
|
||||
|
||||
/**
|
||||
* @brief A struct representing a set of access rights.
|
||||
*
|
||||
* Note that the values of bit positions larger than RS_ACCESS_COUNT is
|
||||
* undefined, and should not be assumed to be 0 (see RS_ACCESS_MASK_FILL).
|
||||
*/
|
||||
typedef struct RS_ACCESS_MASK {
|
||||
RsAccessLimb limbs[SDK_RS_ACCESS_MAX_LIMBS];
|
||||
} RS_ACCESS_MASK;
|
||||
|
||||
/**
|
||||
* @brief A struct representing auxiliary information about each access right.
|
||||
*/
|
||||
typedef struct RS_ACCESS_INFO {
|
||||
NvU32 flags;
|
||||
} RS_ACCESS_INFO;
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* Access right macros */
|
||||
/****************************************************************************/
|
||||
|
||||
#define SDK_RS_ACCESS_LIMB_INDEX(index) ((index) / SDK_RS_ACCESS_LIMB_BITS)
|
||||
#define SDK_RS_ACCESS_LIMB_POS(index) ((index) % SDK_RS_ACCESS_LIMB_BITS)
|
||||
|
||||
#define SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) \
|
||||
((pAccessMask)->limbs[SDK_RS_ACCESS_LIMB_INDEX(index)])
|
||||
#define SDK_RS_ACCESS_OFFSET_MASK(index) \
|
||||
NVBIT_TYPE(SDK_RS_ACCESS_LIMB_POS(index), RsAccessLimb)
|
||||
|
||||
/*!
|
||||
* @brief Checks that accessRight represents a valid access right.
|
||||
*
|
||||
* The valid range of access rights is [0, RS_ACCESS_COUNT).
|
||||
*
|
||||
* @param[in] accessRight The access right value to check
|
||||
*
|
||||
* @return true if accessRight is valid
|
||||
* @return false otherwise
|
||||
*/
|
||||
#define RS_ACCESS_BOUNDS_CHECK(accessRight) \
|
||||
(accessRight < RS_ACCESS_COUNT)
|
||||
|
||||
/*!
|
||||
* @brief Test whether an access right is present in a set
|
||||
*
|
||||
* @param[in] pAccessMask The set of access rights to read
|
||||
* @param[in] index The access right to examine
|
||||
*
|
||||
* @return NV_TRUE if the access right specified by index was present in the set,
|
||||
* and NV_FALSE otherwise
|
||||
*/
|
||||
#define RS_ACCESS_MASK_TEST(pAccessMask, index) \
|
||||
(RS_ACCESS_BOUNDS_CHECK(index) && \
|
||||
(SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) & SDK_RS_ACCESS_OFFSET_MASK(index)) != 0)
|
||||
|
||||
/*!
|
||||
* @brief Add an access right to a mask
|
||||
*
|
||||
* @param[in] pAccessMask The set of access rights to modify
|
||||
* @param[in] index The access right to set
|
||||
*/
|
||||
#define RS_ACCESS_MASK_ADD(pAccessMask, index) \
|
||||
do \
|
||||
{ \
|
||||
if (RS_ACCESS_BOUNDS_CHECK(index)) { \
|
||||
SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) |= SDK_RS_ACCESS_OFFSET_MASK(index); \
|
||||
} \
|
||||
} while (NV_FALSE)
|
||||
|
||||
/*!
|
||||
* @brief Remove an access right from a mask
|
||||
*
|
||||
* @param[in] pAccessMask The set of access rights to modify
|
||||
* @param[in] index The access right to unset
|
||||
*/
|
||||
#define RS_ACCESS_MASK_REMOVE(pAccessMask, index) \
|
||||
do \
|
||||
{ \
|
||||
if (RS_ACCESS_BOUNDS_CHECK(index)) { \
|
||||
SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) &= ~SDK_RS_ACCESS_OFFSET_MASK(index); \
|
||||
} \
|
||||
} while (NV_FALSE)
|
||||
|
||||
/*!
|
||||
* @brief Performs an in-place union between two access right masks
|
||||
*
|
||||
* @param[in,out] pMaskOut The access rights mask to be updated
|
||||
* @param[in] pMaskIn The set of access rights to be added to pMaskOut
|
||||
*/
|
||||
#define RS_ACCESS_MASK_UNION(pMaskOut, pMaskIn) \
|
||||
do \
|
||||
{ \
|
||||
NvLength limb; \
|
||||
for (limb = 0; limb < SDK_RS_ACCESS_MAX_LIMBS; limb++) \
|
||||
{ \
|
||||
SDK_RS_ACCESS_LIMB_ELT(pMaskOut, limb) |= SDK_RS_ACCESS_LIMB_ELT(pMaskIn, limb); \
|
||||
} \
|
||||
} while (NV_FALSE)
|
||||
|
||||
/*!
|
||||
* @brief Performs an in-place subtract of one mask's rights from another
|
||||
*
|
||||
* @param[in,out] pMaskOut The access rights mask to be updated
|
||||
* @param[in] pMaskIn The set of access rights to be removed from pMaskOut
|
||||
*/
|
||||
#define RS_ACCESS_MASK_SUBTRACT(pMaskOut, pMaskIn) \
|
||||
do \
|
||||
{ \
|
||||
NvLength limb; \
|
||||
for (limb = 0; limb < SDK_RS_ACCESS_MAX_LIMBS; limb++) \
|
||||
{ \
|
||||
SDK_RS_ACCESS_LIMB_ELT(pMaskOut, limb) &= ~SDK_RS_ACCESS_LIMB_ELT(pMaskIn, limb); \
|
||||
} \
|
||||
} while (NV_FALSE)
|
||||
|
||||
/*!
|
||||
* @brief Removes all rights from an access rights mask
|
||||
*
|
||||
* @param[in,out] pAccessMask The access rights mask to be updated
|
||||
*/
|
||||
#define RS_ACCESS_MASK_CLEAR(pAccessMask) \
|
||||
do \
|
||||
{ \
|
||||
portMemSet(pAccessMask, 0, sizeof(*pAccessMask)); \
|
||||
} while (NV_FALSE)
|
||||
|
||||
/*!
|
||||
* @brief Adds all rights to an access rights mask
|
||||
*
|
||||
* @param[in,out] pAccessMask The access rights mask to be updated
|
||||
*/
|
||||
#define RS_ACCESS_MASK_FILL(pAccessMask) \
|
||||
do \
|
||||
{ \
|
||||
portMemSet(pAccessMask, 0xff, sizeof(*pAccessMask)); \
|
||||
} while (NV_FALSE)
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* Share definitions */
|
||||
/****************************************************************************/
|
||||
|
||||
//
|
||||
// The usage of Share Policy and the meaning of each share type is documented in
|
||||
// resman/docs/rmapi/resource_server/rm_capabilities.adoc
|
||||
//
|
||||
#define RS_SHARE_TYPE_NONE (0U)
|
||||
#define RS_SHARE_TYPE_ALL (1U)
|
||||
#define RS_SHARE_TYPE_OS_SECURITY_TOKEN (2U)
|
||||
#define RS_SHARE_TYPE_CLIENT (3U)
|
||||
#define RS_SHARE_TYPE_PID (4U)
|
||||
#define RS_SHARE_TYPE_SMC_PARTITION (5U)
|
||||
#define RS_SHARE_TYPE_GPU (6U)
|
||||
#define RS_SHARE_TYPE_FM_CLIENT (7U)
|
||||
// Must be last. Update when a new SHARE_TYPE is added
|
||||
#define RS_SHARE_TYPE_MAX (8U)
|
||||
|
||||
|
||||
//
|
||||
// Use Revoke to remove an existing policy from the list.
|
||||
// Allow is based on OR logic, Require is based on AND logic.
|
||||
// To share a right, at least one Allow (non-Require) must match, and all Require must pass.
|
||||
// If Compose is specified, policies will be added to the list. Otherwise, they will replace the list.
|
||||
//
|
||||
#define RS_SHARE_ACTION_FLAG_REVOKE NVBIT(0)
|
||||
#define RS_SHARE_ACTION_FLAG_REQUIRE NVBIT(1)
|
||||
#define RS_SHARE_ACTION_FLAG_COMPOSE NVBIT(2)
|
||||
|
||||
/****************************************************************************/
|
||||
/* Share flag data structures */
|
||||
/****************************************************************************/
|
||||
|
||||
typedef struct RS_SHARE_POLICY {
|
||||
NvU32 target;
|
||||
RS_ACCESS_MASK accessMask;
|
||||
NvU16 type; ///< RS_SHARE_TYPE_
|
||||
NvU8 action; ///< RS_SHARE_ACTION_
|
||||
} RS_SHARE_POLICY;
|
||||
@@ -1,45 +0,0 @@
|
||||
# Each of these headers is checked for presence with a test #include; a
|
||||
# corresponding #define will be generated in conftest/headers.h.
|
||||
NV_HEADER_PRESENCE_TESTS = \
|
||||
asm/system.h \
|
||||
drm/drm_hdcp.h \
|
||||
drm/display/drm_hdcp.h \
|
||||
drm/display/drm_hdcp_helper.h \
|
||||
drm/drmP.h \
|
||||
drm/drm_aperture.h \
|
||||
drm/drm_atomic_state_helper.h \
|
||||
drm/drm_atomic_uapi.h \
|
||||
drm/drm_fbdev_generic.h \
|
||||
drm/drm_fbdev_ttm.h \
|
||||
drm/drm_client_setup.h \
|
||||
drm/drm_probe_helper.h \
|
||||
drm/clients/drm_client_setup.h \
|
||||
dt-bindings/interconnect/tegra_icc_id.h \
|
||||
generated/autoconf.h \
|
||||
generated/compile.h \
|
||||
generated/utsrelease.h \
|
||||
linux/aperture.h \
|
||||
linux/dma-direct.h \
|
||||
linux/platform/tegra/mc_utils.h \
|
||||
xen/ioemu.h \
|
||||
linux/fence.h \
|
||||
linux/dma-resv.h \
|
||||
soc/tegra/tegra_bpmp.h \
|
||||
linux/platform/tegra/dce/dce-client-ipc.h \
|
||||
linux/nvhost.h \
|
||||
linux/nvhost_t194.h \
|
||||
linux/host1x-next.h \
|
||||
asm/set_memory.h \
|
||||
asm/pgtable_types.h \
|
||||
linux/dma-map-ops.h \
|
||||
sound/hda_codec.h \
|
||||
linux/interconnect.h \
|
||||
linux/ioasid.h \
|
||||
linux/stdarg.h \
|
||||
linux/iosys-map.h \
|
||||
linux/vfio_pci_core.h \
|
||||
linux/cc_platform.h \
|
||||
linux/slub_def.h \
|
||||
asm/mshyperv.h \
|
||||
crypto/sig.h
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __NVIDIA_DRM_CONFTEST_H__
|
||||
#define __NVIDIA_DRM_CONFTEST_H__
|
||||
|
||||
#include "conftest.h"
|
||||
#include "nvtypes.h"
|
||||
|
||||
/*
|
||||
* NOTE: This file is expected to get included at the top before including any
|
||||
* of linux/drm headers.
|
||||
*
|
||||
* The goal is to redefine refcount_dec_and_test and refcount_inc before
|
||||
* including drm header files, so that the drm macro/inline calls to
|
||||
* refcount_dec_and_test* and refcount_inc get redirected to
|
||||
* alternate implementation in this file.
|
||||
*/
|
||||
|
||||
#if NV_IS_EXPORT_SYMBOL_GPL_refcount_inc
|
||||
|
||||
#include <linux/refcount.h>
|
||||
|
||||
#define refcount_inc(__ptr) \
|
||||
do { \
|
||||
atomic_inc(&(__ptr)->refs); \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
|
||||
#if NV_IS_EXPORT_SYMBOL_GPL_refcount_dec_and_test
|
||||
|
||||
#include <linux/refcount.h>
|
||||
|
||||
#define refcount_dec_and_test(__ptr) atomic_dec_and_test(&(__ptr)->refs)
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(NV_DRM_FBDEV_GENERIC_SETUP_PRESENT) && \
|
||||
defined(NV_DRM_APERTURE_REMOVE_CONFLICTING_PCI_FRAMEBUFFERS_PRESENT)
|
||||
#define NV_DRM_FBDEV_AVAILABLE
|
||||
#define NV_DRM_FBDEV_GENERIC_AVAILABLE
|
||||
#endif
|
||||
|
||||
#if defined(NV_DRM_FBDEV_TTM_SETUP_PRESENT) && \
|
||||
defined(NV_DRM_APERTURE_REMOVE_CONFLICTING_PCI_FRAMEBUFFERS_PRESENT)
|
||||
#if IS_ENABLED(CONFIG_DRM_TTM_HELPER)
|
||||
#define NV_DRM_FBDEV_AVAILABLE
|
||||
#define NV_DRM_FBDEV_TTM_AVAILABLE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(NV_DRM_CLIENT_SETUP_PRESENT) && \
|
||||
(defined(NV_DRM_APERTURE_REMOVE_CONFLICTING_PCI_FRAMEBUFFERS_PRESENT) || \
|
||||
defined(NV_APERTURE_REMOVE_CONFLICTING_PCI_DEVICES_PRESENT))
|
||||
// XXX remove dependency on DRM_TTM_HELPER by implementing nvidia-drm's own
|
||||
// .fbdev_probe callback that uses NVKMS kapi
|
||||
#if IS_ENABLED(CONFIG_DRM_TTM_HELPER)
|
||||
#define NV_DRM_FBDEV_AVAILABLE
|
||||
#define NV_DRM_CLIENT_AVAILABLE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Adapt to quirks in FreeBSD's Linux kernel compatibility layer.
|
||||
*/
|
||||
#if defined(NV_BSD)
|
||||
|
||||
#include <linux/rwsem.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/sx.h>
|
||||
|
||||
/* For nv_drm_gem_prime_force_fence_signal */
|
||||
#ifndef spin_is_locked
|
||||
#if ((__FreeBSD_version >= 1500000) && (__FreeBSD_version < 1500018)) || (__FreeBSD_version < 1401501)
|
||||
#define spin_is_locked(lock) mtx_owned(lock.m)
|
||||
#else
|
||||
#define spin_is_locked(lock) mtx_owned(lock)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef rwsem_is_locked
|
||||
#define rwsem_is_locked(sem) (((sem)->sx.sx_lock & (SX_LOCK_SHARED)) \
|
||||
|| ((sem)->sx.sx_lock & ~(SX_LOCK_FLAGMASK & ~SX_LOCK_SHARED)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FreeBSD does not define vm_flags_t in its linuxkpi, since there is already
|
||||
* a FreeBSD vm_flags_t (of a different size) and they don't want the names to
|
||||
* collide. Temporarily redefine it when including nv-mm.h
|
||||
*/
|
||||
#define vm_flags_t unsigned long
|
||||
#include "nv-mm.h"
|
||||
#undef vm_flags_t
|
||||
|
||||
/*
|
||||
* sys/nv.h and nvidia/nv.h have the same header guard
|
||||
* we need to clear it for nvlist_t to get loaded
|
||||
*/
|
||||
#undef _NV_H_
|
||||
#include <sys/nv.h>
|
||||
|
||||
/*
|
||||
* For now just use set_page_dirty as the lock variant
|
||||
* is not ported for FreeBSD. (in progress). This calls
|
||||
* vm_page_dirty. Used in nv-mm.h
|
||||
*/
|
||||
#define set_page_dirty_lock set_page_dirty
|
||||
|
||||
/*
|
||||
* FreeBSD does not implement drm_atomic_state_free, simply
|
||||
* default to drm_atomic_state_put
|
||||
*/
|
||||
#define drm_atomic_state_free drm_atomic_state_put
|
||||
|
||||
#if __FreeBSD_version < 1300000
|
||||
/* redefine LIST_HEAD_INIT to the linux version */
|
||||
#include <linux/list.h>
|
||||
#define LIST_HEAD_INIT(name) LINUX_LIST_HEAD_INIT(name)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FreeBSD currently has only vmf_insert_pfn_prot defined, and it has a
|
||||
* static assert warning not to use it since all of DRM's usages are in
|
||||
* loops with the vm obj lock(s) held. Instead we should use the lkpi
|
||||
* function itself directly. For us none of this applies so we can just
|
||||
* wrap it in our own definition of vmf_insert_pfn
|
||||
*/
|
||||
#ifndef NV_VMF_INSERT_PFN_PRESENT
|
||||
#define NV_VMF_INSERT_PFN_PRESENT 1
|
||||
|
||||
#if __FreeBSD_version < 1300000
|
||||
#define VM_SHARED (1 << 17)
|
||||
|
||||
/* Not present in 12.2 */
|
||||
static inline vm_fault_t
|
||||
lkpi_vmf_insert_pfn_prot_locked(struct vm_area_struct *vma, unsigned long addr,
|
||||
unsigned long pfn, pgprot_t prot)
|
||||
{
|
||||
vm_object_t vm_obj = vma->vm_obj;
|
||||
vm_page_t page;
|
||||
vm_pindex_t pindex;
|
||||
|
||||
VM_OBJECT_ASSERT_WLOCKED(vm_obj);
|
||||
pindex = OFF_TO_IDX(addr - vma->vm_start);
|
||||
if (vma->vm_pfn_count == 0)
|
||||
vma->vm_pfn_first = pindex;
|
||||
MPASS(pindex <= OFF_TO_IDX(vma->vm_end));
|
||||
|
||||
page = vm_page_grab(vm_obj, pindex, VM_ALLOC_NORMAL);
|
||||
if (page == NULL) {
|
||||
page = PHYS_TO_VM_PAGE(IDX_TO_OFF(pfn));
|
||||
vm_page_xbusy(page);
|
||||
if (vm_page_insert(page, vm_obj, pindex)) {
|
||||
vm_page_xunbusy(page);
|
||||
return (VM_FAULT_OOM);
|
||||
}
|
||||
page->valid = VM_PAGE_BITS_ALL;
|
||||
}
|
||||
pmap_page_set_memattr(page, pgprot2cachemode(prot));
|
||||
vma->vm_pfn_count++;
|
||||
|
||||
return (VM_FAULT_NOPAGE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline vm_fault_t
|
||||
vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
|
||||
unsigned long pfn)
|
||||
{
|
||||
vm_fault_t ret;
|
||||
|
||||
VM_OBJECT_WLOCK(vma->vm_obj);
|
||||
ret = lkpi_vmf_insert_pfn_prot_locked(vma, addr, pfn, vma->vm_page_prot);
|
||||
VM_OBJECT_WUNLOCK(vma->vm_obj);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* defined(NV_BSD) */
|
||||
|
||||
#endif /* defined(__NVIDIA_DRM_CONFTEST_H__) */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2023, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
|
||||
#include "nvidia-drm-os-interface.h"
|
||||
#include "nvidia-drm.h"
|
||||
|
||||
#include "nvidia-drm-conftest.h"
|
||||
|
||||
#if defined(NV_DRM_AVAILABLE)
|
||||
|
||||
MODULE_PARM_DESC(
|
||||
modeset,
|
||||
"Enable atomic kernel modesetting (1 = enable, 0 = disable (default))");
|
||||
module_param_named(modeset, nv_drm_modeset_module_param, bool, 0400);
|
||||
|
||||
#if defined(NV_DRM_FBDEV_AVAILABLE)
|
||||
MODULE_PARM_DESC(
|
||||
fbdev,
|
||||
"Create a framebuffer device (1 = enable (default), 0 = disable)");
|
||||
module_param_named(fbdev, nv_drm_fbdev_module_param, bool, 0400);
|
||||
#endif
|
||||
|
||||
#endif /* NV_DRM_AVAILABLE */
|
||||
|
||||
/*************************************************************************
|
||||
* Linux loading support code.
|
||||
*************************************************************************/
|
||||
|
||||
static int __init nv_linux_drm_init(void)
|
||||
{
|
||||
return nv_drm_init();
|
||||
}
|
||||
|
||||
static void __exit nv_linux_drm_exit(void)
|
||||
{
|
||||
nv_drm_exit();
|
||||
}
|
||||
|
||||
module_init(nv_linux_drm_init);
|
||||
module_exit(nv_linux_drm_exit);
|
||||
|
||||
MODULE_LICENSE("Dual MIT/GPL");
|
||||
|
||||
MODULE_INFO(supported, "external");
|
||||
MODULE_VERSION(NV_VERSION_STRING);
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2025, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __NVIDIA_DRM_OS_INTERFACE_H__
|
||||
#define __NVIDIA_DRM_OS_INTERFACE_H__
|
||||
|
||||
#include "nvidia-drm-conftest.h" /* NV_DRM_AVAILABLE */
|
||||
|
||||
#include "nvtypes.h"
|
||||
|
||||
#if defined(NV_DRM_AVAILABLE)
|
||||
|
||||
#include "linux/dma-fence.h"
|
||||
|
||||
#if defined(NV_LINUX) || defined(NV_BSD)
|
||||
#include "nv-kthread-q.h"
|
||||
#include "linux/spinlock.h"
|
||||
|
||||
typedef struct nv_drm_workthread {
|
||||
spinlock_t lock;
|
||||
struct nv_kthread_q q;
|
||||
bool shutting_down;
|
||||
} nv_drm_workthread;
|
||||
|
||||
typedef nv_kthread_q_item_t nv_drm_work;
|
||||
|
||||
#else
|
||||
#error "Need to define deferred work primitives for this OS"
|
||||
#endif
|
||||
|
||||
#if defined(NV_LINUX) || defined(NV_BSD)
|
||||
#include "nv-timer.h"
|
||||
|
||||
typedef struct nv_timer nv_drm_timer;
|
||||
|
||||
#else
|
||||
#error "Need to define kernel timer callback primitives for this OS"
|
||||
#endif
|
||||
|
||||
struct page;
|
||||
|
||||
/* Set to true when the atomic modeset feature is enabled. */
|
||||
extern bool nv_drm_modeset_module_param;
|
||||
#if defined(NV_DRM_FBDEV_AVAILABLE)
|
||||
/* Set to true when the nvidia-drm driver should install a framebuffer device */
|
||||
extern bool nv_drm_fbdev_module_param;
|
||||
#endif
|
||||
|
||||
void *nv_drm_calloc(size_t nmemb, size_t size);
|
||||
|
||||
void nv_drm_free(void *ptr);
|
||||
|
||||
void nv_drm_write_combine_flush(void);
|
||||
|
||||
int nv_drm_lock_user_pages(unsigned long address,
|
||||
unsigned long pages_count, struct page ***pages);
|
||||
|
||||
void nv_drm_unlock_user_pages(unsigned long pages_count, struct page **pages);
|
||||
|
||||
void *nv_drm_vmap(struct page **pages, unsigned long pages_count, bool cached);
|
||||
|
||||
void nv_drm_vunmap(void *address);
|
||||
|
||||
bool nv_drm_workthread_init(nv_drm_workthread *worker, const char *name);
|
||||
|
||||
/* Can be called concurrently with nv_drm_workthread_add_work() */
|
||||
void nv_drm_workthread_shutdown(nv_drm_workthread *worker);
|
||||
|
||||
void nv_drm_workthread_work_init(nv_drm_work *work,
|
||||
void (*callback)(void *),
|
||||
void *arg);
|
||||
|
||||
/* Can be called concurrently with nv_drm_workthread_shutdown() */
|
||||
int nv_drm_workthread_add_work(nv_drm_workthread *worker, nv_drm_work *work);
|
||||
|
||||
void nv_drm_timer_setup(nv_drm_timer *timer,
|
||||
void (*callback)(nv_drm_timer *nv_drm_timer));
|
||||
|
||||
void nv_drm_mod_timer(nv_drm_timer *timer, unsigned long relative_timeout_ms);
|
||||
|
||||
unsigned long nv_drm_timer_now(void);
|
||||
|
||||
unsigned long nv_drm_timeout_from_ms(NvU64 relative_timeout_ms);
|
||||
|
||||
int nv_drm_create_sync_file(struct dma_fence *fence);
|
||||
|
||||
struct dma_fence *nv_drm_sync_file_get_fence(int fd);
|
||||
|
||||
void nv_drm_yield(void);
|
||||
|
||||
#endif /* defined(NV_DRM_AVAILABLE) */
|
||||
|
||||
#endif /* __NVIDIA_DRM_OS_INTERFACE_H__ */
|
||||
@@ -1,33 +0,0 @@
|
||||
###########################################################################
|
||||
# Kbuild fragment for nvidia-drm.ko
|
||||
###########################################################################
|
||||
|
||||
# Get our source file list and conftest list from the common file
|
||||
include $(src)/nvidia-drm/nvidia-drm-sources.mk
|
||||
|
||||
# Linux-specific sources
|
||||
NVIDIA_DRM_SOURCES += nvidia-drm/nvidia-drm-linux.c
|
||||
|
||||
#
|
||||
# Define NVIDIA_DRM_{SOURCES,OBJECTS}
|
||||
#
|
||||
|
||||
NVIDIA_DRM_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_DRM_SOURCES))
|
||||
|
||||
obj-m += nvidia-drm.o
|
||||
nvidia-drm-y := $(NVIDIA_DRM_OBJECTS)
|
||||
|
||||
NVIDIA_DRM_KO = nvidia-drm/nvidia-drm.ko
|
||||
|
||||
NV_KERNEL_MODULE_TARGETS += $(NVIDIA_DRM_KO)
|
||||
|
||||
#
|
||||
# Define nvidia-drm.ko-specific CFLAGS.
|
||||
#
|
||||
|
||||
NVIDIA_DRM_CFLAGS += -I$(src)/nvidia-drm
|
||||
NVIDIA_DRM_CFLAGS += -UDEBUG -U_DEBUG -DNDEBUG -DNV_BUILD_MODULE_INSTANCES=0
|
||||
|
||||
$(call ASSIGN_PER_OBJ_CFLAGS, $(NVIDIA_DRM_OBJECTS), $(NVIDIA_DRM_CFLAGS))
|
||||
|
||||
NV_OBJECTS_DEPEND_ON_CONFTEST += $(NVIDIA_DRM_OBJECTS)
|
||||
@@ -1,329 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "nv-kthread-q.h"
|
||||
#include "nv-list-helpers.h"
|
||||
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/bug.h>
|
||||
|
||||
// Today's implementation is a little simpler and more limited than the
|
||||
// API description allows for in nv-kthread-q.h. Details include:
|
||||
//
|
||||
// 1. Each nv_kthread_q instance is a first-in, first-out queue.
|
||||
//
|
||||
// 2. Each nv_kthread_q instance is serviced by exactly one kthread.
|
||||
//
|
||||
// You can create any number of queues, each of which gets its own
|
||||
// named kernel thread (kthread). You can then insert arbitrary functions
|
||||
// into the queue, and those functions will be run in the context of the
|
||||
// queue's kthread.
|
||||
|
||||
#ifndef WARN
|
||||
// Only *really* old kernels (2.6.9) end up here. Just use a simple printk
|
||||
// to implement this, because such kernels won't be supported much longer.
|
||||
#define WARN(condition, format...) ({ \
|
||||
int __ret_warn_on = !!(condition); \
|
||||
if (unlikely(__ret_warn_on)) \
|
||||
printk(KERN_ERR format); \
|
||||
unlikely(__ret_warn_on); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define NVQ_WARN(fmt, ...) \
|
||||
do { \
|
||||
if (in_interrupt()) { \
|
||||
WARN(1, "nv_kthread_q: [in interrupt]: " fmt, \
|
||||
##__VA_ARGS__); \
|
||||
} \
|
||||
else { \
|
||||
WARN(1, "nv_kthread_q: task: %s: " fmt, \
|
||||
current->comm, \
|
||||
##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int _main_loop(void *args)
|
||||
{
|
||||
nv_kthread_q_t *q = (nv_kthread_q_t *)args;
|
||||
nv_kthread_q_item_t *q_item = NULL;
|
||||
unsigned long flags;
|
||||
|
||||
while (1) {
|
||||
// Normally this thread is never interrupted. However,
|
||||
// down_interruptible (instead of down) is called here,
|
||||
// in order to avoid being classified as a potentially
|
||||
// hung task, by the kernel watchdog.
|
||||
while (down_interruptible(&q->q_sem))
|
||||
NVQ_WARN("Interrupted during semaphore wait\n");
|
||||
|
||||
if (atomic_read(&q->main_loop_should_exit))
|
||||
break;
|
||||
|
||||
spin_lock_irqsave(&q->q_lock, flags);
|
||||
|
||||
// The q_sem semaphore prevents us from getting here unless there is
|
||||
// at least one item in the list, so an empty list indicates a bug.
|
||||
if (unlikely(list_empty(&q->q_list_head))) {
|
||||
spin_unlock_irqrestore(&q->q_lock, flags);
|
||||
NVQ_WARN("_main_loop: Empty queue: q: 0x%p\n", q);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Consume one item from the queue
|
||||
q_item = list_first_entry(&q->q_list_head,
|
||||
nv_kthread_q_item_t,
|
||||
q_list_node);
|
||||
|
||||
list_del_init(&q_item->q_list_node);
|
||||
|
||||
spin_unlock_irqrestore(&q->q_lock, flags);
|
||||
|
||||
// Run the item
|
||||
q_item->function_to_run(q_item->function_args);
|
||||
|
||||
// Make debugging a little simpler by clearing this between runs:
|
||||
q_item = NULL;
|
||||
}
|
||||
|
||||
while (!kthread_should_stop())
|
||||
schedule();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nv_kthread_q_stop(nv_kthread_q_t *q)
|
||||
{
|
||||
// check if queue has been properly initialized
|
||||
if (unlikely(!q->q_kthread))
|
||||
return;
|
||||
|
||||
nv_kthread_q_flush(q);
|
||||
|
||||
// If this assertion fires, then a caller likely either broke the API rules,
|
||||
// by adding items after calling nv_kthread_q_stop, or possibly messed up
|
||||
// with inadequate flushing of self-rescheduling q_items.
|
||||
if (unlikely(!list_empty(&q->q_list_head)))
|
||||
NVQ_WARN("list not empty after flushing\n");
|
||||
|
||||
if (likely(!atomic_read(&q->main_loop_should_exit))) {
|
||||
|
||||
atomic_set(&q->main_loop_should_exit, 1);
|
||||
|
||||
// Wake up the kthread so that it can see that it needs to stop:
|
||||
up(&q->q_sem);
|
||||
|
||||
kthread_stop(q->q_kthread);
|
||||
q->q_kthread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// When CONFIG_VMAP_STACK is defined, the kernel thread stack allocator used by
|
||||
// kthread_create_on_node relies on a 2 entry, per-core cache to minimize
|
||||
// vmalloc invocations. The cache is NUMA-unaware, so when there is a hit, the
|
||||
// stack location ends up being a function of the core assigned to the current
|
||||
// thread, instead of being a function of the specified NUMA node. The cache was
|
||||
// added to the kernel in commit ac496bf48d97f2503eaa353996a4dd5e4383eaf0
|
||||
// ("fork: Optimize task creation by caching two thread stacks per CPU if
|
||||
// CONFIG_VMAP_STACK=y")
|
||||
//
|
||||
// To work around the problematic cache, we create up to three kernel threads
|
||||
// -If the first thread's stack is resident on the preferred node, return this
|
||||
// thread.
|
||||
// -Otherwise, create a second thread. If its stack is resident on the
|
||||
// preferred node, stop the first thread and return this one.
|
||||
// -Otherwise, create a third thread. The stack allocator does not find a
|
||||
// cached stack, and so falls back to vmalloc, which takes the NUMA hint into
|
||||
// consideration. The first two threads are then stopped.
|
||||
//
|
||||
// When CONFIG_VMAP_STACK is not defined, the first kernel thread is returned.
|
||||
//
|
||||
// This function is never invoked when there is no NUMA preference (preferred
|
||||
// node is NUMA_NO_NODE).
|
||||
static struct task_struct *thread_create_on_node(int (*threadfn)(void *data),
|
||||
nv_kthread_q_t *q,
|
||||
int preferred_node,
|
||||
const char *q_name)
|
||||
{
|
||||
|
||||
unsigned i, j;
|
||||
static const unsigned attempts = 3;
|
||||
struct task_struct *thread[3];
|
||||
|
||||
for (i = 0;; i++) {
|
||||
struct page *stack;
|
||||
|
||||
thread[i] = kthread_create_on_node(threadfn, q, preferred_node, q_name);
|
||||
|
||||
if (unlikely(IS_ERR(thread[i]))) {
|
||||
|
||||
// Instead of failing, pick the previous thread, even if its
|
||||
// stack is not allocated on the preferred node.
|
||||
if (i > 0)
|
||||
i--;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// vmalloc is not used to allocate the stack, so simply return the
|
||||
// thread, even if its stack may not be allocated on the preferred node
|
||||
if (!is_vmalloc_addr(thread[i]->stack))
|
||||
break;
|
||||
|
||||
// Ran out of attempts - return thread even if its stack may not be
|
||||
// allocated on the preferred node
|
||||
if (i == (attempts - 1))
|
||||
break;
|
||||
|
||||
// Get the NUMA node where the first page of the stack is resident. If
|
||||
// it is the preferred node, select this thread.
|
||||
stack = vmalloc_to_page(thread[i]->stack);
|
||||
if (page_to_nid(stack) == preferred_node)
|
||||
break;
|
||||
}
|
||||
|
||||
for (j = i; j > 0; j--)
|
||||
kthread_stop(thread[j - 1]);
|
||||
|
||||
return thread[i];
|
||||
}
|
||||
|
||||
int nv_kthread_q_init_on_node(nv_kthread_q_t *q, const char *q_name, int preferred_node)
|
||||
{
|
||||
memset(q, 0, sizeof(*q));
|
||||
|
||||
INIT_LIST_HEAD(&q->q_list_head);
|
||||
spin_lock_init(&q->q_lock);
|
||||
sema_init(&q->q_sem, 0);
|
||||
|
||||
if (preferred_node == NV_KTHREAD_NO_NODE) {
|
||||
q->q_kthread = kthread_create(_main_loop, q, q_name);
|
||||
}
|
||||
else {
|
||||
q->q_kthread = thread_create_on_node(_main_loop, q, preferred_node, q_name);
|
||||
}
|
||||
|
||||
if (IS_ERR(q->q_kthread)) {
|
||||
int err = PTR_ERR(q->q_kthread);
|
||||
|
||||
// Clear q_kthread before returning so that nv_kthread_q_stop() can be
|
||||
// safely called on it making error handling easier.
|
||||
q->q_kthread = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
wake_up_process(q->q_kthread);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nv_kthread_q_init(nv_kthread_q_t *q, const char *qname)
|
||||
{
|
||||
return nv_kthread_q_init_on_node(q, qname, NV_KTHREAD_NO_NODE);
|
||||
}
|
||||
|
||||
// Returns true (non-zero) if the item was actually scheduled, and false if the
|
||||
// item was already pending in a queue.
|
||||
static int _raw_q_schedule(nv_kthread_q_t *q, nv_kthread_q_item_t *q_item)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret = 1;
|
||||
|
||||
spin_lock_irqsave(&q->q_lock, flags);
|
||||
|
||||
if (likely(list_empty(&q_item->q_list_node)))
|
||||
list_add_tail(&q_item->q_list_node, &q->q_list_head);
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
spin_unlock_irqrestore(&q->q_lock, flags);
|
||||
|
||||
if (likely(ret))
|
||||
up(&q->q_sem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void nv_kthread_q_item_init(nv_kthread_q_item_t *q_item,
|
||||
nv_q_func_t function_to_run,
|
||||
void *function_args)
|
||||
{
|
||||
INIT_LIST_HEAD(&q_item->q_list_node);
|
||||
q_item->function_to_run = function_to_run;
|
||||
q_item->function_args = function_args;
|
||||
}
|
||||
|
||||
// Returns true (non-zero) if the q_item got scheduled, false otherwise.
|
||||
int nv_kthread_q_schedule_q_item(nv_kthread_q_t *q,
|
||||
nv_kthread_q_item_t *q_item)
|
||||
{
|
||||
if (unlikely(atomic_read(&q->main_loop_should_exit))) {
|
||||
NVQ_WARN("Not allowed: nv_kthread_q_schedule_q_item was "
|
||||
"called with a non-alive q: 0x%p\n", q);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _raw_q_schedule(q, q_item);
|
||||
}
|
||||
|
||||
static void _q_flush_function(void *args)
|
||||
{
|
||||
struct completion *completion = (struct completion *)args;
|
||||
complete(completion);
|
||||
}
|
||||
|
||||
|
||||
static void _raw_q_flush(nv_kthread_q_t *q)
|
||||
{
|
||||
nv_kthread_q_item_t q_item;
|
||||
DECLARE_COMPLETION_ONSTACK(completion);
|
||||
|
||||
nv_kthread_q_item_init(&q_item, _q_flush_function, &completion);
|
||||
|
||||
_raw_q_schedule(q, &q_item);
|
||||
|
||||
// Wait for the flush item to run. Once it has run, then all of the
|
||||
// previously queued items in front of it will have run, so that means
|
||||
// the flush is complete.
|
||||
wait_for_completion(&completion);
|
||||
}
|
||||
|
||||
void nv_kthread_q_flush(nv_kthread_q_t *q)
|
||||
{
|
||||
if (unlikely(atomic_read(&q->main_loop_should_exit))) {
|
||||
NVQ_WARN("Not allowed: nv_kthread_q_flush was called after "
|
||||
"nv_kthread_q_stop. q: 0x%p\n", q);
|
||||
return;
|
||||
}
|
||||
|
||||
// This 2x flush is not a typing mistake. The queue really does have to be
|
||||
// flushed twice, in order to take care of the case of a q_item that
|
||||
// reschedules itself.
|
||||
_raw_q_flush(q);
|
||||
_raw_q_flush(q);
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_AEAD_H
|
||||
#define CRYPTLIB_AEAD_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Authenticated Encryption with Associated data (AEAD) Cryptography Primitives
|
||||
*=====================================================================================
|
||||
*/
|
||||
|
||||
#if LIBSPDM_AEAD_GCM_SUPPORT
|
||||
/**
|
||||
* Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated
|
||||
* data.
|
||||
*
|
||||
* iv_size must be 12, otherwise false is returned.
|
||||
* key_size must be 16 or 32, otherwise false is returned.
|
||||
* tag_size must be 12, 13, 14, 15, 16, otherwise false is returned.
|
||||
*
|
||||
* @param[in] key Pointer to the encryption key.
|
||||
* @param[in] key_size Size of the encryption key in bytes.
|
||||
* @param[in] iv Pointer to the IV value.
|
||||
* @param[in] iv_size Size of the IV value in bytes.
|
||||
* @param[in] a_data Pointer to the additional authenticated data.
|
||||
* @param[in] a_data_size Size of the additional authenticated data in bytes.
|
||||
* @param[in] data_in Pointer to the input data buffer to be encrypted.
|
||||
* @param[in] data_in_size Size of the input data buffer in bytes.
|
||||
* @param[out] tag_out Pointer to a buffer that receives the authentication tag output.
|
||||
* @param[in] tag_size Size of the authentication tag in bytes.
|
||||
* @param[out] data_out Pointer to a buffer that receives the encryption output.
|
||||
* @param[out] data_out_size Size of the output data buffer in bytes.
|
||||
*
|
||||
* @retval true AEAD AES-GCM authenticated encryption succeeded.
|
||||
* @retval false AEAD AES-GCM authenticated encryption failed.
|
||||
**/
|
||||
extern bool libspdm_aead_aes_gcm_encrypt(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag_out, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size);
|
||||
|
||||
/**
|
||||
* Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated
|
||||
* data.
|
||||
*
|
||||
* iv_size must be 12, otherwise false is returned.
|
||||
* key_size must be 16 or 32, otherwise false is returned.
|
||||
* tag_size must be 12, 13, 14, 15, 16, otherwise false is returned.
|
||||
*
|
||||
* If data verification fails, false is returned.
|
||||
*
|
||||
* @param[in] key Pointer to the encryption key.
|
||||
* @param[in] key_size Size of the encryption key in bytes.
|
||||
* @param[in] iv Pointer to the IV value.
|
||||
* @param[in] iv_size Size of the IV value in bytes.
|
||||
* @param[in] a_data Pointer to the additional authenticated data.
|
||||
* @param[in] a_data_size Size of the additional authenticated data in bytes.
|
||||
* @param[in] data_in Pointer to the input data buffer to be decrypted.
|
||||
* @param[in] data_in_size Size of the input data buffer in bytes.
|
||||
* @param[in] tag Pointer to a buffer that contains the authentication tag.
|
||||
* @param[in] tag_size Size of the authentication tag in bytes.
|
||||
* @param[out] data_out Pointer to a buffer that receives the decryption output.
|
||||
* @param[out] data_out_size Size of the output data buffer in bytes.
|
||||
*
|
||||
* @retval true AEAD AES-GCM authenticated decryption succeeded.
|
||||
* @retval false AEAD AES-GCM authenticated decryption failed.
|
||||
**/
|
||||
extern bool libspdm_aead_aes_gcm_decrypt(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size);
|
||||
#endif /* LIBSPDM_AEAD_GCM_SUPPORT */
|
||||
|
||||
#if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
|
||||
/**
|
||||
* Performs AEAD ChaCha20Poly1305 authenticated encryption on a data buffer and additional
|
||||
* authenticated data.
|
||||
*
|
||||
* iv_size must be 12, otherwise false is returned.
|
||||
* key_size must be 32, otherwise false is returned.
|
||||
* tag_size must be 16, otherwise false is returned.
|
||||
*
|
||||
* @param[in] key Pointer to the encryption key.
|
||||
* @param[in] key_size Size of the encryption key in bytes.
|
||||
* @param[in] iv Pointer to the IV value.
|
||||
* @param[in] iv_size Size of the IV value in bytes.
|
||||
* @param[in] a_data Pointer to the additional authenticated data.
|
||||
* @param[in] a_data_size Size of the additional authenticated data in bytes.
|
||||
* @param[in] data_in Pointer to the input data buffer to be encrypted.
|
||||
* @param[in] data_in_size Size of the input data buffer in bytes.
|
||||
* @param[out] tag_out Pointer to a buffer that receives the authentication tag output.
|
||||
* @param[in] tag_size Size of the authentication tag in bytes.
|
||||
* @param[out] data_out Pointer to a buffer that receives the encryption output.
|
||||
* @param[out] data_out_size Size of the output data buffer in bytes.
|
||||
*
|
||||
* @retval true AEAD ChaCha20Poly1305 authenticated encryption succeeded.
|
||||
* @retval false AEAD ChaCha20Poly1305 authenticated encryption failed.
|
||||
**/
|
||||
extern bool libspdm_aead_chacha20_poly1305_encrypt(
|
||||
const uint8_t *key, size_t key_size, const uint8_t *iv,
|
||||
size_t iv_size, const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size, uint8_t *tag_out,
|
||||
size_t tag_size, uint8_t *data_out, size_t *data_out_size);
|
||||
|
||||
/**
|
||||
* Performs AEAD ChaCha20Poly1305 authenticated decryption on a data buffer and additional authenticated data (AAD).
|
||||
*
|
||||
* iv_size must be 12, otherwise false is returned.
|
||||
* key_size must be 32, otherwise false is returned.
|
||||
* tag_size must be 16, otherwise false is returned.
|
||||
*
|
||||
* If data verification fails, false is returned.
|
||||
*
|
||||
* @param[in] key Pointer to the encryption key.
|
||||
* @param[in] key_size Size of the encryption key in bytes.
|
||||
* @param[in] iv Pointer to the IV value.
|
||||
* @param[in] iv_size Size of the IV value in bytes.
|
||||
* @param[in] a_data Pointer to the additional authenticated data.
|
||||
* @param[in] a_data_size Size of the additional authenticated data in bytes.
|
||||
* @param[in] data_in Pointer to the input data buffer to be decrypted.
|
||||
* @param[in] data_in_size Size of the input data buffer in bytes.
|
||||
* @param[in] tag Pointer to a buffer that contains the authentication tag.
|
||||
* @param[in] tag_size Size of the authentication tag in bytes.
|
||||
* @param[out] data_out Pointer to a buffer that receives the decryption output.
|
||||
* @param[out] data_out_size Size of the output data buffer in bytes.
|
||||
*
|
||||
* @retval true AEAD ChaCha20Poly1305 authenticated decryption succeeded.
|
||||
* @retval false AEAD ChaCha20Poly1305 authenticated decryption failed.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_aead_chacha20_poly1305_decrypt(
|
||||
const uint8_t *key, size_t key_size, const uint8_t *iv,
|
||||
size_t iv_size, const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size, const uint8_t *tag,
|
||||
size_t tag_size, uint8_t *data_out, size_t *data_out_size);
|
||||
#endif /* LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT */
|
||||
|
||||
#if LIBSPDM_AEAD_SM4_SUPPORT
|
||||
/**
|
||||
* Performs AEAD SM4-GCM authenticated encryption on a data buffer and additional authenticated
|
||||
* data.
|
||||
*
|
||||
* iv_size must be 12, otherwise false is returned.
|
||||
* key_size must be 16, otherwise false is returned.
|
||||
* tag_size must be 16, otherwise false is returned.
|
||||
*
|
||||
* @param[in] key Pointer to the encryption key.
|
||||
* @param[in] key_size Size of the encryption key in bytes.
|
||||
* @param[in] iv Pointer to the IV value.
|
||||
* @param[in] iv_size Size of the IV value in bytes.
|
||||
* @param[in] a_data Pointer to the additional authenticated data.
|
||||
* @param[in] a_data_size Size of the additional authenticated data in bytes.
|
||||
* @param[in] data_in Pointer to the input data buffer to be encrypted.
|
||||
* @param[in] data_in_size Size of the input data buffer in bytes.
|
||||
* @param[out] tag_out Pointer to a buffer that receives the authentication tag output.
|
||||
* @param[in] tag_size Size of the authentication tag in bytes.
|
||||
* @param[out] data_out Pointer to a buffer that receives the encryption output.
|
||||
* @param[out] data_out_size Size of the output data buffer in bytes.
|
||||
*
|
||||
* @retval true AEAD SM4-GCM authenticated encryption succeeded.
|
||||
* @retval false AEAD SM4-GCM authenticated encryption failed.
|
||||
**/
|
||||
extern bool libspdm_aead_sm4_gcm_encrypt(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag_out, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size);
|
||||
|
||||
/**
|
||||
* Performs AEAD SM4-GCM authenticated decryption on a data buffer and additional authenticated
|
||||
* data.
|
||||
*
|
||||
* iv_size must be 12, otherwise false is returned.
|
||||
* key_size must be 16, otherwise false is returned.
|
||||
* tag_size must be 16, otherwise false is returned.
|
||||
*
|
||||
* If data verification fails, false is returned.
|
||||
*
|
||||
* @param[in] key Pointer to the encryption key.
|
||||
* @param[in] key_size Size of the encryption key in bytes.
|
||||
* @param[in] iv Pointer to the IV value.
|
||||
* @param[in] iv_size Size of the IV value in bytes.
|
||||
* @param[in] a_data Pointer to the additional authenticated data.
|
||||
* @param[in] a_data_size Size of the additional authenticated data in bytes.
|
||||
* @param[in] data_in Pointer to the input data buffer to be decrypted.
|
||||
* @param[in] data_in_size Size of the input data buffer in bytes.
|
||||
* @param[in] tag Pointer to a buffer that contains the authentication tag.
|
||||
* @param[in] tag_size Size of the authentication tag in bytes.
|
||||
* @param[out] data_out Pointer to a buffer that receives the decryption output.
|
||||
* @param[out] data_out_size Size of the output data buffer in bytes.
|
||||
*
|
||||
* @retval true AEAD SM4-GCM authenticated decryption succeeded.
|
||||
* @retval false AEAD SM4-GCM authenticated decryption failed.
|
||||
**/
|
||||
extern bool libspdm_aead_sm4_gcm_decrypt(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size);
|
||||
#endif /* LIBSPDM_AEAD_SM4_SUPPORT */
|
||||
|
||||
#endif /* CRYPTLIB_AEAD_H */
|
||||
@@ -1,416 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2024 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_CERT_H
|
||||
#define CRYPTLIB_CERT_H
|
||||
|
||||
#if LIBSPDM_CERT_PARSE_SUPPORT
|
||||
|
||||
/**
|
||||
* Retrieve the tag and length of the tag.
|
||||
*
|
||||
* @param ptr The position in the ASN.1 data.
|
||||
* @param end End of data.
|
||||
* @param length The variable that will receive the length.
|
||||
* @param tag The expected tag.
|
||||
*
|
||||
* @retval true Get tag successful.
|
||||
* @retval false Failed to get tag or tag not match.
|
||||
**/
|
||||
extern bool libspdm_asn1_get_tag(uint8_t **ptr, const uint8_t *end, size_t *length, uint32_t tag);
|
||||
|
||||
/**
|
||||
* Retrieve the subject bytes from one X.509 certificate.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If subject_size is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] cert_subject Pointer to the retrieved certificate subject bytes.
|
||||
* @param[in, out] subject_size The size in bytes of the cert_subject buffer on input,
|
||||
* and the size of buffer returned cert_subject on output.
|
||||
*
|
||||
* @retval true If the subject_size is not equal 0. The certificate subject retrieved successfully.
|
||||
* @retval true If the subject_size is equal 0. The certificate parse successful. But the cert doesn't have subject.
|
||||
* @retval false If the subject_size is not equal 0. The certificate subject retrieved successfully.But the subject_size is too small for the result.
|
||||
* @retval false If the subject_size is equal 0. Invalid certificate.
|
||||
**/
|
||||
extern bool libspdm_x509_get_subject_name(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *cert_subject,
|
||||
size_t *subject_size);
|
||||
|
||||
/**
|
||||
* Retrieve the version from one X.509 certificate.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If cert_size is 0, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] version Pointer to the retrieved version integer.
|
||||
*
|
||||
* @retval true
|
||||
* @retval false
|
||||
**/
|
||||
extern bool libspdm_x509_get_version(const uint8_t *cert, size_t cert_size, size_t *version);
|
||||
|
||||
/**
|
||||
* Retrieve the serialNumber from one X.509 certificate.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If cert_size is 0, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] serial_number Pointer to the retrieved certificate serial_number bytes.
|
||||
* @param[in, out] serial_number_size The size in bytes of the serial_number buffer on input,
|
||||
* and the size of buffer returned serial_number on output.
|
||||
*
|
||||
* @retval true
|
||||
* @retval false
|
||||
**/
|
||||
extern bool libspdm_x509_get_serial_number(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *serial_number,
|
||||
size_t *serial_number_size);
|
||||
|
||||
#if LIBSPDM_ADDITIONAL_CHECK_CERT
|
||||
/**
|
||||
* Retrieve the signature algorithm from one X.509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] oid Signature algorithm Object identifier buffer.
|
||||
* @param[in,out] oid_size Signature algorithm Object identifier buffer size.
|
||||
*
|
||||
* @retval true if the oid_size is equal 0, the cert parse successfully, but cert doesn't have signature algo.
|
||||
* @retval true if the oid_size is not equal 0, the cert parse and get signature algo successfully.
|
||||
* @retval false if the oid_size is equal 0, the cert parse failed.
|
||||
* @retval false if the oid_size is not equal 0, the cert parse and get signature algo successfully, but the input buffer size is small.
|
||||
**/
|
||||
extern bool libspdm_x509_get_signature_algorithm(const uint8_t *cert,
|
||||
size_t cert_size, uint8_t *oid,
|
||||
size_t *oid_size);
|
||||
#endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
|
||||
|
||||
/**
|
||||
* Retrieve the issuer bytes from one X.509 certificate.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If issuer_size is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] cert_issuer Pointer to the retrieved certificate subject bytes.
|
||||
* @param[in, out] issuer_size The size in bytes of the cert_issuer buffer on input,
|
||||
* and the size of buffer returned cert_issuer on output.
|
||||
*
|
||||
* @retval true If the issuer_size is not equal 0. The certificate issuer retrieved successfully.
|
||||
* @retval true If the issuer_size is equal 0. The certificate parse successful. But the cert doesn't have issuer.
|
||||
* @retval false If the issuer_size is not equal 0. The certificate issuer retrieved successfully. But the issuer_size is too small for the result.
|
||||
* @retval false If the issuer_size is equal 0. Invalid certificate.
|
||||
**/
|
||||
extern bool libspdm_x509_get_issuer_name(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *cert_issuer,
|
||||
size_t *issuer_size);
|
||||
|
||||
/**
|
||||
* Retrieve Extension data from one X.509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[in] oid Object identifier buffer
|
||||
* @param[in] oid_size Object identifier buffer size
|
||||
* @param[out] extension_data Extension bytes.
|
||||
* @param[in, out] extension_data_size Extension bytes size.
|
||||
*
|
||||
* @retval true If the returned extension_data_size == 0, it means that cert and oid are valid, but the oid extension is not found;
|
||||
* If the returned extension_data_size != 0, it means that cert and oid are valid, and the oid extension is found;
|
||||
* @retval false If the returned extension_data_size == 0, it means that cert or oid are invalid;
|
||||
* If the returned extension_data_size != 0, it means that cert and oid are valid, and the oid extension is found,
|
||||
* but the store buffer is too small.
|
||||
**/
|
||||
extern bool libspdm_x509_get_extension_data(const uint8_t *cert, size_t cert_size,
|
||||
const uint8_t *oid, size_t oid_size,
|
||||
uint8_t *extension_data,
|
||||
size_t *extension_data_size);
|
||||
|
||||
/**
|
||||
* Retrieve the Validity from one X.509 certificate
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If CertIssuerSize is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] from notBefore Pointer to date_time object.
|
||||
* @param[in,out] from_size notBefore date_time object size.
|
||||
* @param[out] to notAfter Pointer to date_time object.
|
||||
* @param[in,out] to_size notAfter date_time object size.
|
||||
*
|
||||
* Note: libspdm_x509_compare_date_time to compare date_time oject
|
||||
* x509SetDateTime to get a date_time object from a date_time_str
|
||||
*
|
||||
* @retval true if the from_size and from_size are not equal 0.
|
||||
* The certificate Validity retrieved successfully.
|
||||
* @retval true if the from_size and from_size are equal 0.
|
||||
* The certificate Validity does not exist.
|
||||
* @retval false if the from_size and from_size are not equal 0.
|
||||
* The certificate Validity retrieved successfully, but the input buffer size is small.
|
||||
* @retval false if the from_size and from_size are equal 0.
|
||||
* Invalid certificate, or Validity retrieve failed.
|
||||
**/
|
||||
extern bool libspdm_x509_get_validity(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *from, size_t *from_size, uint8_t *to,
|
||||
size_t *to_size);
|
||||
|
||||
/**
|
||||
* Format a date_time object into DataTime buffer
|
||||
*
|
||||
* If date_time_str is NULL, then return false.
|
||||
* If date_time_size is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] date_time_str date_time string like YYYYMMDDhhmmssZ
|
||||
* Ref: https://www.w3.org/TR/NOTE-datetime
|
||||
* Z stand for UTC time
|
||||
* @param[out] date_time Pointer to a date_time object.
|
||||
* @param[in,out] date_time_size date_time object buffer size.
|
||||
*
|
||||
* @retval true
|
||||
* @retval false
|
||||
**/
|
||||
extern bool libspdm_x509_set_date_time(const char *date_time_str, void *date_time,
|
||||
size_t *date_time_size);
|
||||
|
||||
/**
|
||||
* Compare date_time1 object and date_time2 object.
|
||||
*
|
||||
* If date_time1 is NULL, then return -2.
|
||||
* If date_time2 is NULL, then return -2.
|
||||
* If date_time1 == date_time2, then return 0
|
||||
* If date_time1 > date_time2, then return 1
|
||||
* If date_time1 < date_time2, then return -1
|
||||
*
|
||||
* @param[in] date_time1 Pointer to a date_time Ojbect
|
||||
* @param[in] date_time2 Pointer to a date_time Object
|
||||
*
|
||||
* @retval 0 If date_time1 == date_time2
|
||||
* @retval 1 If date_time1 > date_time2
|
||||
* @retval -1 If date_time1 < date_time2
|
||||
**/
|
||||
extern int32_t libspdm_x509_compare_date_time(const void *date_time1, const void *date_time2);
|
||||
|
||||
/**
|
||||
* Retrieve the key usage from one X.509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] usage Key usage (LIBSPDM_CRYPTO_X509_KU_*)
|
||||
*
|
||||
* @retval true if the usage is no equal 0. The certificate key usage retrieved successfully.
|
||||
* @retval true if the usage is equal 0. The certificate parse successfully, but the cert doesn't have key usage.
|
||||
* @retval false Invalid certificate, or usage is NULL.
|
||||
**/
|
||||
extern bool libspdm_x509_get_key_usage(const uint8_t *cert, size_t cert_size, size_t *usage);
|
||||
|
||||
/**
|
||||
* Retrieve the Extended key usage from one X.509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] usage Key usage bytes.
|
||||
* @param[in, out] usage_size Key usage buffer size in bytes.
|
||||
*
|
||||
* @retval true If the returned usage_size == 0, it means that cert and oid are valid, but the Extended key usage is not found;
|
||||
* If the returned usage_size != 0, it means that cert and oid are valid, and the Extended key usage is found;
|
||||
* @retval false If the returned usage_size == 0, it means that cert or oid are invalid;
|
||||
* If the returned usage_size != 0, it means that cert and oid are valid, and the Extended key usage is found,
|
||||
* but the store buffer is too small.
|
||||
**/
|
||||
extern bool libspdm_x509_get_extended_key_usage(const uint8_t *cert,
|
||||
size_t cert_size, uint8_t *usage,
|
||||
size_t *usage_size);
|
||||
|
||||
/**
|
||||
* Retrieve the basic constraints from one X.509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] basic_constraints Basic constraints bytes.
|
||||
* @param[in, out] basic_constraints_size Basic constraints buffer size in bytes.
|
||||
*
|
||||
* @retval true If the returned basic_constraints_size == 0, it means that cert and oid are valid, but the basic_constraints is not found;
|
||||
* If the returned basic_constraints_size != 0, it means that cert and oid are valid, and the basic_constraints is found;
|
||||
* @retval false If the returned basic_constraints_size == 0, it means that cert or oid are invalid;
|
||||
* If the returned basic_constraints_size != 0, it means that cert and oid are valid, and the basic_constraints is found,
|
||||
* but the store buffer is too small.
|
||||
**/
|
||||
extern bool libspdm_x509_get_extended_basic_constraints(const uint8_t *cert,
|
||||
size_t cert_size,
|
||||
uint8_t *basic_constraints,
|
||||
size_t *basic_constraints_size);
|
||||
|
||||
/**
|
||||
* Verify one X509 certificate was issued by the trusted CA.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If ca_cert is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate to be verified.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[in] ca_cert Pointer to the DER-encoded trusted CA certificate.
|
||||
* @param[in] ca_cert_size Size of the CA Certificate in bytes.
|
||||
*
|
||||
* @retval true The certificate was issued by the trusted CA.
|
||||
* @retval false Invalid certificate or the certificate was not issued by the given
|
||||
* trusted CA.
|
||||
* @retval false This interface is not supported.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_x509_verify_cert(const uint8_t *cert, size_t cert_size,
|
||||
const uint8_t *ca_cert, size_t ca_cert_size);
|
||||
|
||||
/**
|
||||
* Verify one X509 certificate was issued by the trusted CA.
|
||||
*
|
||||
* @param[in] cert_chain One or more ASN.1 DER-encoded X.509 certificates
|
||||
* where the first certificate is signed by the Root
|
||||
* Certificate or is the Root Certificate itself. and
|
||||
* subsequent certificate is signed by the preceding
|
||||
* certificate.
|
||||
* @param[in] cert_chain_length Total length of the certificate chain, in bytes.
|
||||
*
|
||||
* @param[in] root_cert Trusted Root Certificate buffer.
|
||||
*
|
||||
* @param[in] root_cert_length Trusted Root Certificate buffer length.
|
||||
*
|
||||
* @retval true All certificates were issued by the first certificate in X509Certchain.
|
||||
* @retval false Invalid certificate or the certificate was not issued by the given
|
||||
* trusted CA.
|
||||
**/
|
||||
extern bool libspdm_x509_verify_cert_chain(const uint8_t *root_cert, size_t root_cert_length,
|
||||
const uint8_t *cert_chain,
|
||||
size_t cert_chain_length);
|
||||
|
||||
/**
|
||||
* Get one X509 certificate from cert_chain.
|
||||
*
|
||||
* @param[in] cert_chain One or more ASN.1 DER-encoded X.509 certificates
|
||||
* where the first certificate is signed by the Root
|
||||
* Certificate or is the Root Certificate itself. and
|
||||
* subsequent certificate is signed by the preceding
|
||||
* certificate.
|
||||
* @param[in] cert_chain_length Total length of the certificate chain, in bytes.
|
||||
*
|
||||
* @param[in] cert_index Index of certificate. If index is -1 indicates the
|
||||
* last certificate in cert_chain.
|
||||
*
|
||||
* @param[out] cert The certificate at the index of cert_chain.
|
||||
* @param[out] cert_length The length certificate at the index of cert_chain.
|
||||
*
|
||||
* @retval true Success.
|
||||
* @retval false Failed to get certificate from certificate chain.
|
||||
**/
|
||||
extern bool libspdm_x509_get_cert_from_cert_chain(const uint8_t *cert_chain,
|
||||
size_t cert_chain_length,
|
||||
const int32_t cert_index, const uint8_t **cert,
|
||||
size_t *cert_length);
|
||||
|
||||
#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
|
||||
/**
|
||||
* Retrieve the RSA public key from one DER-encoded X509 certificate.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] rsa_context Pointer to newly generated RSA context which contain the retrieved
|
||||
* RSA public key component. Use libspdm_rsa_free() function to free the
|
||||
* resource.
|
||||
*
|
||||
* @retval true RSA public key was retrieved successfully.
|
||||
* @retval false Fail to retrieve RSA public key from X509 certificate.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_rsa_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **rsa_context);
|
||||
#endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
|
||||
|
||||
#if LIBSPDM_ECDSA_SUPPORT
|
||||
/**
|
||||
* Retrieve the EC public key from one DER-encoded X509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] ec_context Pointer to newly generated EC DSA context which contain the retrieved
|
||||
* EC public key component. Use libspdm_ec_free() function to free the
|
||||
* resource.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If ec_context is NULL, then return false.
|
||||
*
|
||||
* @retval true EC public key was retrieved successfully.
|
||||
* @retval false Fail to retrieve EC public key from X509 certificate.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_ec_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **ec_context);
|
||||
#endif /* LIBSPDM_ECDSA_SUPPORT */
|
||||
|
||||
#if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
|
||||
/**
|
||||
* Retrieve the Ed public key from one DER-encoded X509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] ecd_context Pointer to newly generated Ed DSA context which contain the retrieved
|
||||
* Ed public key component. Use libspdm_ecd_free() function to free the
|
||||
* resource.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If ecd_context is NULL, then return false.
|
||||
*
|
||||
* @retval true Ed public key was retrieved successfully.
|
||||
* @retval false Fail to retrieve Ed public key from X509 certificate.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_ecd_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **ecd_context);
|
||||
#endif /* (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT) */
|
||||
|
||||
#if LIBSPDM_SM2_DSA_SUPPORT
|
||||
/**
|
||||
* Retrieve the sm2 public key from one DER-encoded X509 certificate.
|
||||
*
|
||||
* @param[in] cert Pointer to the DER-encoded X509 certificate.
|
||||
* @param[in] cert_size Size of the X509 certificate in bytes.
|
||||
* @param[out] sm2_context Pointer to newly generated sm2 context which contain the retrieved
|
||||
* sm2 public key component. Use sm2_free() function to free the
|
||||
* resource.
|
||||
*
|
||||
* If cert is NULL, then return false.
|
||||
* If sm2_context is NULL, then return false.
|
||||
*
|
||||
* @retval true sm2 public key was retrieved successfully.
|
||||
* @retval false Fail to retrieve sm2 public key from X509 certificate.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_sm2_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **sm2_context);
|
||||
#endif /* LIBSPDM_SM2_DSA_SUPPORT */
|
||||
|
||||
#endif /* LIBSPDM_CERT_PARSE_SUPPORT */
|
||||
|
||||
#endif /* CRYPTLIB_CERT_H */
|
||||
@@ -1,98 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_DH_H
|
||||
#define CRYPTLIB_DH_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Diffie-Hellman Key Exchange Primitives
|
||||
*=====================================================================================
|
||||
*/
|
||||
|
||||
#if LIBSPDM_FFDHE_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one Diffie-Hellman context for subsequent use with the NID.
|
||||
*
|
||||
* @param nid cipher NID
|
||||
*
|
||||
* @return Pointer to the Diffie-Hellman context that has been initialized.
|
||||
* If the allocations fails, libspdm_dh_new_by_nid() returns NULL.
|
||||
* If the interface is not supported, libspdm_dh_new_by_nid() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_dh_new_by_nid(size_t nid);
|
||||
|
||||
/**
|
||||
* Release the specified DH context.
|
||||
*
|
||||
* @param[in] dh_context Pointer to the DH context to be released.
|
||||
**/
|
||||
void libspdm_dh_free(void *dh_context);
|
||||
|
||||
/**
|
||||
* Generates DH public key.
|
||||
*
|
||||
* This function generates random secret exponent, and computes the public key, which is
|
||||
* returned via parameter public_key and public_key_size. DH context is updated accordingly.
|
||||
* If the public_key buffer is too small to hold the public key, false is returned and
|
||||
* public_key_size is set to the required buffer size to obtain the public key.
|
||||
*
|
||||
* If dh_context is NULL, then return false.
|
||||
* If public_key_size is NULL, then return false.
|
||||
* If public_key_size is large enough but public_key is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* For FFDHE2048, the public_size is 256.
|
||||
* For FFDHE3072, the public_size is 384.
|
||||
* For FFDHE4096, the public_size is 512.
|
||||
*
|
||||
* @param[in, out] dh_context Pointer to the DH context.
|
||||
* @param[out] public_key Pointer to the buffer to receive generated public key.
|
||||
* @param[in, out] public_key_size On input, the size of public_key buffer in bytes.
|
||||
* On output, the size of data returned in public_key buffer in
|
||||
* bytes.
|
||||
*
|
||||
* @retval true DH public key generation succeeded.
|
||||
* @retval false DH public key generation failed.
|
||||
* @retval false public_key_size is not large enough.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_dh_generate_key(void *dh_context, uint8_t *public_key, size_t *public_key_size);
|
||||
|
||||
/**
|
||||
* Computes exchanged common key.
|
||||
*
|
||||
* Given peer's public key, this function computes the exchanged common key, based on its own
|
||||
* context including value of prime modulus and random secret exponent.
|
||||
*
|
||||
* If dh_context is NULL, then return false.
|
||||
* If peer_public_key is NULL, then return false.
|
||||
* If key_size is NULL, then return false.
|
||||
* If key is NULL, then return false.
|
||||
* If key_size is not large enough, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* For FFDHE2048, the peer_public_size and key_size is 256.
|
||||
* For FFDHE3072, the peer_public_size and key_size is 384.
|
||||
* For FFDHE4096, the peer_public_size and key_size is 512.
|
||||
*
|
||||
* @param[in, out] dh_context Pointer to the DH context.
|
||||
* @param[in] peer_public_key Pointer to the peer's public key.
|
||||
* @param[in] peer_public_key_size size of peer's public key in bytes.
|
||||
* @param[out] key Pointer to the buffer to receive generated key.
|
||||
* @param[in, out] key_size On input, the size of key buffer in bytes.
|
||||
* On output, the size of data returned in key buffer in
|
||||
* bytes.
|
||||
*
|
||||
* @retval true DH exchanged key generation succeeded.
|
||||
* @retval false DH exchanged key generation failed.
|
||||
* @retval false key_size is not large enough.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_dh_compute_key(void *dh_context, const uint8_t *peer_public_key,
|
||||
size_t peer_public_key_size, uint8_t *key,
|
||||
size_t *key_size);
|
||||
#endif /* LIBSPDM_FFDHE_SUPPORT */
|
||||
#endif /* CRYPTLIB_DH_H */
|
||||
@@ -1,246 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_EC_H
|
||||
#define CRYPTLIB_EC_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Elliptic Curve Primitives
|
||||
*=====================================================================================*/
|
||||
|
||||
#if (LIBSPDM_ECDHE_SUPPORT) || (LIBSPDM_ECDSA_SUPPORT)
|
||||
/**
|
||||
* Allocates and Initializes one Elliptic Curve context for subsequent use with the NID.
|
||||
*
|
||||
* @param nid cipher NID
|
||||
*
|
||||
* @return Pointer to the Elliptic Curve context that has been initialized.
|
||||
* If the allocations fails, libspdm_ec_new_by_nid() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_ec_new_by_nid(size_t nid);
|
||||
|
||||
/**
|
||||
* Release the specified EC context.
|
||||
*
|
||||
* @param[in] ec_context Pointer to the EC context to be released.
|
||||
**/
|
||||
extern void libspdm_ec_free(void *ec_context);
|
||||
|
||||
#if LIBSPDM_FIPS_MODE
|
||||
/**
|
||||
* Sets the private key component into the established EC context.
|
||||
*
|
||||
* For P-256, the private_key_size is 32 byte.
|
||||
* For P-384, the private_key_size is 48 byte.
|
||||
* For P-521, the private_key_size is 66 byte.
|
||||
*
|
||||
* @param[in, out] ec_context Pointer to EC context being set.
|
||||
* @param[in] private_key Pointer to the private key buffer.
|
||||
* @param[in] private_key_size The size of private key buffer in bytes.
|
||||
*
|
||||
* @retval true EC private key component was set successfully.
|
||||
* @retval false Invalid EC private key component.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_ec_set_priv_key(void *ec_context, const uint8_t *private_key,
|
||||
size_t private_key_size);
|
||||
|
||||
/**
|
||||
* Sets the public key component into the established EC context.
|
||||
*
|
||||
* For P-256, the public_size is 64. first 32-byte is X, second 32-byte is Y.
|
||||
* For P-384, the public_size is 96. first 48-byte is X, second 48-byte is Y.
|
||||
* For P-521, the public_size is 132. first 66-byte is X, second 66-byte is Y.
|
||||
*
|
||||
* @param[in, out] ec_context Pointer to EC context being set.
|
||||
* @param[in] public Pointer to the buffer to receive generated public X,Y.
|
||||
* @param[in] public_size The size of public buffer in bytes.
|
||||
*
|
||||
* @retval true EC public key component was set successfully.
|
||||
* @retval false Invalid EC public key component.
|
||||
**/
|
||||
extern bool libspdm_ec_set_pub_key(void *ec_context, const uint8_t *public_key,
|
||||
size_t public_key_size);
|
||||
#endif /* LIBSPDM_FIPS_MODE */
|
||||
|
||||
#endif /* (LIBSPDM_ECDHE_SUPPORT) || (LIBSPDM_ECDSA_SUPPORT) */
|
||||
|
||||
#if LIBSPDM_ECDHE_SUPPORT
|
||||
/**
|
||||
* Generates EC key and returns EC public key (X, Y).
|
||||
*
|
||||
* This function generates random secret, and computes the public key (X, Y), which is
|
||||
* returned via parameter public, public_size.
|
||||
* X is the first half of public with size being public_size / 2,
|
||||
* Y is the second half of public with size being public_size / 2.
|
||||
* EC context is updated accordingly.
|
||||
* If the public buffer is too small to hold the public X, Y, false is returned and
|
||||
* public_size is set to the required buffer size to obtain the public X, Y.
|
||||
*
|
||||
* For P-256, the public_size is 64. first 32-byte is X, second 32-byte is Y.
|
||||
* For P-384, the public_size is 96. first 48-byte is X, second 48-byte is Y.
|
||||
* For P-521, the public_size is 132. first 66-byte is X, second 66-byte is Y.
|
||||
*
|
||||
* If ec_context is NULL, then return false.
|
||||
* If public_size is NULL, then return false.
|
||||
* If public_size is large enough but public is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] ec_context Pointer to the EC context.
|
||||
* @param[out] public Pointer to the buffer to receive generated public X,Y.
|
||||
* @param[in, out] public_size On input, the size of public buffer in bytes.
|
||||
* On output, the size of data returned in public buffer in bytes.
|
||||
*
|
||||
* @retval true EC public X,Y generation succeeded.
|
||||
* @retval false EC public X,Y generation failed.
|
||||
* @retval false public_size is not large enough.
|
||||
**/
|
||||
extern bool libspdm_ec_generate_key(void *ec_context, uint8_t *public_key, size_t *public_key_size);
|
||||
|
||||
/**
|
||||
* Computes exchanged common key.
|
||||
*
|
||||
* Given peer's public key (X, Y), this function computes the exchanged common key,
|
||||
* based on its own context including value of curve parameter and random secret.
|
||||
* X is the first half of peer_public with size being peer_public_size / 2,
|
||||
* Y is the second half of peer_public with size being peer_public_size / 2.
|
||||
*
|
||||
* If ec_context is NULL, then return false.
|
||||
* If peer_public is NULL, then return false.
|
||||
* If peer_public_size is 0, then return false.
|
||||
* If key is NULL, then return false.
|
||||
* If key_size is not large enough, then return false.
|
||||
*
|
||||
* For P-256, the peer_public_size is 64. first 32-byte is X, second 32-byte is Y.
|
||||
* The key_size is 32.
|
||||
* For P-384, the peer_public_size is 96. first 48-byte is X, second 48-byte is Y.
|
||||
* The key_size is 48.
|
||||
* For P-521, the peer_public_size is 132. first 66-byte is X, second 66-byte is Y.
|
||||
* The key_size is 66.
|
||||
*
|
||||
* @param[in, out] ec_context Pointer to the EC context.
|
||||
* @param[in] peer_public Pointer to the peer's public X,Y.
|
||||
* @param[in] peer_public_size Size of peer's public X,Y in bytes.
|
||||
* @param[out] key Pointer to the buffer to receive generated key.
|
||||
* @param[in, out] key_size On input, the size of key buffer in bytes.
|
||||
* On output, the size of data returned in key buffer in bytes.
|
||||
*
|
||||
* @retval true EC exchanged key generation succeeded.
|
||||
* @retval false EC exchanged key generation failed.
|
||||
* @retval false key_size is not large enough.
|
||||
**/
|
||||
extern bool libspdm_ec_compute_key(void *ec_context, const uint8_t *peer_public,
|
||||
size_t peer_public_size, uint8_t *key,
|
||||
size_t *key_size);
|
||||
#endif /* LIBSPDM_ECDHE_SUPPORT */
|
||||
|
||||
#if LIBSPDM_ECDSA_SUPPORT
|
||||
/**
|
||||
* Generates Elliptic Curve context from DER-encoded public key data.
|
||||
*
|
||||
* The public key is ASN.1 DER-encoded as RFC7250 describes,
|
||||
* namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
|
||||
*
|
||||
* @param[in] der_data Pointer to the DER-encoded public key data.
|
||||
* @param[in] der_size Size of the DER-encoded public key data in bytes.
|
||||
* @param[out] ec_context Pointer to newly generated EC context which contains the
|
||||
* EC public key component.
|
||||
* Use libspdm_ec_free() function to free the resource.
|
||||
*
|
||||
* If der_data is NULL, then return false.
|
||||
* If ec_context is NULL, then return false.
|
||||
*
|
||||
* @retval true EC context was generated successfully.
|
||||
* @retval false Invalid DER public key data.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_ec_get_public_key_from_der(const uint8_t *der_data,
|
||||
size_t der_size,
|
||||
void **ec_context);
|
||||
|
||||
/**
|
||||
* Carries out the EC-DSA signature.
|
||||
*
|
||||
* This function carries out the EC-DSA signature.
|
||||
* If the signature buffer is too small to hold the contents of signature, false
|
||||
* is returned and sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If ec_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256,
|
||||
* SHA3_384, SHA3_512.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
*
|
||||
* For P-256, the sig_size is 64. first 32-byte is R, second 32-byte is S.
|
||||
* For P-384, the sig_size is 96. first 48-byte is R, second 48-byte is S.
|
||||
* For P-521, the sig_size is 132. first 66-byte is R, second 66-byte is S.
|
||||
*
|
||||
* @param[in] ec_context Pointer to EC context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be signed.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive EC-DSA signature.
|
||||
* @param[in, out] sig_size 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 EC-DSA.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
**/
|
||||
extern bool libspdm_ecdsa_sign(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size);
|
||||
|
||||
#if LIBSPDM_FIPS_MODE
|
||||
/**
|
||||
* Carries out the EC-DSA signature with caller input random function. This API can be used for FIPS test.
|
||||
*
|
||||
* @param[in] ec_context Pointer to EC context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be signed.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive EC-DSA signature.
|
||||
* @param[in, out] sig_size On input, the size of signature buffer in bytes.
|
||||
* On output, the size of data returned in signature buffer in bytes.
|
||||
* @param[in] random_func random number function
|
||||
*
|
||||
* @retval true signature successfully generated in EC-DSA.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
**/
|
||||
extern bool libspdm_ecdsa_sign_ex(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size,
|
||||
int (*random_func)(void *, unsigned char *, size_t));
|
||||
#endif/*LIBSPDM_FIPS_MODE*/
|
||||
|
||||
/**
|
||||
* Verifies the EC-DSA signature.
|
||||
*
|
||||
* If ec_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If signature is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256,
|
||||
* SHA3_384, SHA3_512.
|
||||
*
|
||||
* For P-256, the sig_size is 64. first 32-byte is R, second 32-byte is S.
|
||||
* For P-384, the sig_size is 96. first 48-byte is R, second 48-byte is S.
|
||||
* For P-521, the sig_size is 132. first 66-byte is R, second 66-byte is S.
|
||||
*
|
||||
* @param[in] ec_context Pointer to EC context for signature verification.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be checked.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[in] signature Pointer to EC-DSA signature to be verified.
|
||||
* @param[in] sig_size Size of signature in bytes.
|
||||
*
|
||||
* @retval true Valid signature encoded in EC-DSA.
|
||||
* @retval false Invalid signature or invalid EC context.
|
||||
**/
|
||||
extern bool libspdm_ecdsa_verify(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
#endif /* LIBSPDM_ECDSA_SUPPORT */
|
||||
#endif /* CRYPTLIB_EC_H */
|
||||
@@ -1,173 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_ECD_H
|
||||
#define CRYPTLIB_ECD_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Edwards-Curve Primitives
|
||||
*=====================================================================================*/
|
||||
|
||||
#if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
|
||||
/**
|
||||
* Allocates and Initializes one Edwards-Curve context for subsequent use with the NID.
|
||||
*
|
||||
* @param nid cipher NID
|
||||
*
|
||||
* @return Pointer to the Edwards-Curve context that has been initialized.
|
||||
* If the allocations fails, libspdm_ecd_new_by_nid() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_ecd_new_by_nid(size_t nid);
|
||||
|
||||
/**
|
||||
* Generates Edwards-Curve context from DER-encoded public key data.
|
||||
*
|
||||
* The public key is ASN.1 DER-encoded as RFC7250 describes,
|
||||
* namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
|
||||
*
|
||||
* @param[in] der_data Pointer to the DER-encoded public key data.
|
||||
* @param[in] der_size Size of the DER-encoded public key data in bytes.
|
||||
* @param[out] ec_context Pointer to newly generated Ed context which contains the
|
||||
* Ed public key component.
|
||||
* Use libspdm_ecd_free() function to free the resource.
|
||||
*
|
||||
* If der_data is NULL, then return false.
|
||||
* If ecd_context is NULL, then return false.
|
||||
*
|
||||
* @retval true Ed context was generated successfully.
|
||||
* @retval false Invalid DER public key data.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_ecd_get_public_key_from_der(const uint8_t *der_data,
|
||||
size_t der_size,
|
||||
void **ecd_context);
|
||||
|
||||
/**
|
||||
* Release the specified Ed context.
|
||||
*
|
||||
* @param[in] ecd_context Pointer to the Ed context to be released.
|
||||
**/
|
||||
extern void libspdm_ecd_free(void *ecd_context);
|
||||
|
||||
/**
|
||||
* Sets the public key component into the established Ed context.
|
||||
*
|
||||
* For ed25519, the public_size is 32.
|
||||
* For ed448, the public_size is 57.
|
||||
*
|
||||
* @param[in, out] ecd_context Pointer to Ed context being set.
|
||||
* @param[in] public_key Pointer to the buffer to receive generated public X,Y.
|
||||
* @param[in] public_size The size of public buffer in bytes.
|
||||
*
|
||||
* @retval true Ed public key component was set successfully.
|
||||
* @retval false Invalid EC public key component.
|
||||
**/
|
||||
extern bool libspdm_ecd_set_pub_key(void *ecd_context, const uint8_t *public_key,
|
||||
size_t public_key_size);
|
||||
|
||||
/**
|
||||
* Sets the private key component into the established Ed context.
|
||||
*
|
||||
* For ed25519, the private_size is 32.
|
||||
* For ed448, the private_size is 57.
|
||||
*
|
||||
* @param[in, out] ecd_context Pointer to Ed context being set.
|
||||
* @param[in] private Pointer to the buffer to receive generated private X,Y.
|
||||
* @param[in] private_size The size of private buffer in bytes.
|
||||
*
|
||||
* @retval true Ed private key component was set successfully.
|
||||
* @retval false Invalid EC private key component.
|
||||
*
|
||||
**/
|
||||
bool libspdm_ecd_set_pri_key(void *ecd_context, const uint8_t *private_key,
|
||||
size_t private_key_size);
|
||||
|
||||
/**
|
||||
* Gets the public key component from the established Ed context.
|
||||
*
|
||||
* For ed25519, the public_size is 32.
|
||||
* For ed448, the public_size is 57.
|
||||
*
|
||||
* @param[in, out] ecd_context Pointer to Ed context being set.
|
||||
* @param[out] public Pointer to the buffer to receive generated public X,Y.
|
||||
* @param[in, out] public_size On input, the size of public buffer in bytes.
|
||||
* On output, the size of data returned in public buffer in bytes.
|
||||
*
|
||||
* @retval true Ed key component was retrieved successfully.
|
||||
* @retval false Invalid EC public key component.
|
||||
**/
|
||||
extern bool libspdm_ecd_get_pub_key(void *ecd_context, uint8_t *public_key,
|
||||
size_t *public_key_size);
|
||||
|
||||
/**
|
||||
* Carries out the Ed-DSA signature.
|
||||
*
|
||||
* This function carries out the Ed-DSA signature.
|
||||
* If the signature buffer is too small to hold the contents of signature, false
|
||||
* is returned and sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If ecd_context is NULL, then return false.
|
||||
* If message is NULL, then return false.
|
||||
* hash_nid must be NULL.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
*
|
||||
* For ed25519, context must be NULL and context_size must be 0.
|
||||
* For ed448, context must be maximum of 255 octets.
|
||||
*
|
||||
* For ed25519, the sig_size is 64. first 32-byte is R, second 32-byte is S.
|
||||
* For ed448, the sig_size is 114. first 57-byte is R, second 57-byte is S.
|
||||
*
|
||||
* @param[in] ecd_context Pointer to Ed context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] context The EDDSA signing context.
|
||||
* @param[in] context_size Size of EDDSA signing context.
|
||||
* @param[in] message Pointer to octet message to be signed (before hash).
|
||||
* @param[in] size size of the message in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive Ed-DSA signature.
|
||||
* @param[in, out] sig_size 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 Ed-DSA.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
**/
|
||||
extern bool libspdm_eddsa_sign(const void *ecd_context, size_t hash_nid,
|
||||
const uint8_t *context, size_t context_size,
|
||||
const uint8_t *message, size_t size, uint8_t *signature,
|
||||
size_t *sig_size);
|
||||
|
||||
/**
|
||||
* Verifies the Ed-DSA signature.
|
||||
*
|
||||
* If ecd_context is NULL, then return false.
|
||||
* If message is NULL, then return false.
|
||||
* If signature is NULL, then return false.
|
||||
* hash_nid must be NULL.
|
||||
*
|
||||
* For ed25519, context must be NULL and context_size must be 0.
|
||||
* For ed448, context must be maximum of 255 octets.
|
||||
*
|
||||
* For ed25519, the sig_size is 64. first 32-byte is R, second 32-byte is S.
|
||||
* For ed448, the sig_size is 114. first 57-byte is R, second 57-byte is S.
|
||||
*
|
||||
* @param[in] ecd_context Pointer to Ed context for signature verification.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] context The EDDSA signing context.
|
||||
* @param[in] context_size Size of EDDSA signing context.
|
||||
* @param[in] message Pointer to octet message to be checked (before hash).
|
||||
* @param[in] size Size of the message in bytes.
|
||||
* @param[in] signature Pointer to Ed-DSA signature to be verified.
|
||||
* @param[in] sig_size Size of signature in bytes.
|
||||
*
|
||||
* @retval true Valid signature encoded in Ed-DSA.
|
||||
* @retval false Invalid signature or invalid Ed context.
|
||||
**/
|
||||
extern bool libspdm_eddsa_verify(const void *ecd_context, size_t hash_nid,
|
||||
const uint8_t *context, size_t context_size,
|
||||
const uint8_t *message, size_t size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
#endif /* (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT) */
|
||||
#endif /* CRYPTLIB_ECD_H */
|
||||
@@ -1,772 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_HASH_H
|
||||
#define CRYPTLIB_HASH_H
|
||||
|
||||
/* SHA-256 digest size in bytes. */
|
||||
#define LIBSPDM_SHA256_DIGEST_SIZE 32
|
||||
|
||||
/* SHA-384 digest size in bytes. */
|
||||
#define LIBSPDM_SHA384_DIGEST_SIZE 48
|
||||
|
||||
/* SHA-512 digest size in bytes. */
|
||||
#define LIBSPDM_SHA512_DIGEST_SIZE 64
|
||||
|
||||
/* SHA3-256 digest size in bytes. */
|
||||
#define LIBSPDM_SHA3_256_DIGEST_SIZE 32
|
||||
|
||||
/* SHA3-384 digest size in bytes. */
|
||||
#define LIBSPDM_SHA3_384_DIGEST_SIZE 48
|
||||
|
||||
/* SHA3-512 digest size in bytes. */
|
||||
#define LIBSPDM_SHA3_512_DIGEST_SIZE 64
|
||||
|
||||
/* SM3_256 digest size in bytes. */
|
||||
#define LIBSPDM_SM3_256_DIGEST_SIZE 32
|
||||
|
||||
/*=====================================================================================
|
||||
* One-way cryptographic hash SHA2 primitives.
|
||||
*=====================================================================================
|
||||
*/
|
||||
#if LIBSPDM_SHA256_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SHA-256 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, sha256_new() returns NULL. *
|
||||
**/
|
||||
extern void *libspdm_sha256_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sha256_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sha256_free(void *sha256_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed to by sha256_context as SHA-256 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sha256_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sha256_context Pointer to SHA-256 context being initialized.
|
||||
*
|
||||
* @retval true SHA-256 context initialization succeeded.
|
||||
* @retval false SHA-256 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sha256_init(void *sha256_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SHA-256 context.
|
||||
*
|
||||
* If sha256_context is NULL, then return false.
|
||||
* If new_sha256_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sha256_context Pointer to SHA-256 context being copied.
|
||||
* @param[out] new_sha256_context Pointer to new SHA-256 context.
|
||||
*
|
||||
* @retval true SHA-256 context copy succeeded.
|
||||
* @retval false SHA-256 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha256_duplicate(const void *sha256_context, void *new_sha256_context);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates SHA-256 context.
|
||||
*
|
||||
* This function performs SHA-256 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.
|
||||
* SHA-256 context should be already correctly initialized by libspdm_sha256_init(), and must not
|
||||
* have been finalized by libspdm_sha256_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sha256_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha256_context Pointer to the SHA-256 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SHA-256 data digest succeeded.
|
||||
* @retval false SHA-256 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sha256_update(void *sha256_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the SHA-256 digest value.
|
||||
*
|
||||
* This function completes SHA-256 hash computation and populates the digest value into
|
||||
* the specified memory. After this function has been called, the SHA-256 context cannot
|
||||
* be used again. SHA-256 context should be already correctly initialized by libspdm_sha256_init(),
|
||||
* and must not have been finalized by libspdm_sha256_final(). Behavior with invalid SHA-256 context
|
||||
* is undefined.
|
||||
*
|
||||
* If sha256_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha256_context Pointer to the SHA-256 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA-256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true SHA-256 digest computation succeeded.
|
||||
* @retval false SHA-256 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_sha256_final(void *sha256_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SHA-256 message digest of an input data buffer.
|
||||
*
|
||||
* This function performs the SHA-256 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA-256 digest value (32 bytes).
|
||||
*
|
||||
* @retval true SHA-256 digest computation succeeded.
|
||||
* @retval false SHA-256 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha256_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SHA256_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA384_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SHA-384 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_sha384_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sha384_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sha384_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sha384_free(void *sha384_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed to by sha384_context as SHA-384 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sha384_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sha384_context Pointer to SHA-384 context being initialized.
|
||||
*
|
||||
* @retval true SHA-384 context initialization succeeded.
|
||||
* @retval false SHA-384 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sha384_init(void *sha384_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SHA-384 context.
|
||||
*
|
||||
* If sha384_context is NULL, then return false.
|
||||
* If new_sha384_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sha384_context Pointer to SHA-384 context being copied.
|
||||
* @param[out] new_sha384_context Pointer to new SHA-384 context.
|
||||
*
|
||||
* @retval true SHA-384 context copy succeeded.
|
||||
* @retval false SHA-384 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha384_duplicate(const void *sha384_context, void *new_sha384_context);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates SHA-384 context.
|
||||
*
|
||||
* This function performs SHA-384 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.
|
||||
* SHA-384 context should be already correctly initialized by libspdm_sha384_init(), and must not
|
||||
* have been finalized by libspdm_sha384_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sha384_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha384_context Pointer to the SHA-384 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SHA-384 data digest succeeded.
|
||||
* @retval false SHA-384 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sha384_update(void *sha384_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the SHA-384 digest value.
|
||||
*
|
||||
* This function completes SHA-384 hash computation and populates the digest value into
|
||||
* the specified memory. After this function has been called, the SHA-384 context cannot
|
||||
* be used again. SHA-384 context should be already correctly initialized by libspdm_sha384_init(),
|
||||
* and must not have been finalized by libspdm_sha384_final(). Behavior with invalid SHA-384 context
|
||||
* is undefined.
|
||||
*
|
||||
* If sha384_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha384_context Pointer to the SHA-384 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA-384 digest
|
||||
* value (48 bytes).
|
||||
*
|
||||
* @retval true SHA-384 digest computation succeeded.
|
||||
* @retval false SHA-384 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_sha384_final(void *sha384_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SHA-384 message digest of an input data buffer.
|
||||
*
|
||||
* This function performs the SHA-384 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA-384 digest value (48 bytes).
|
||||
*
|
||||
* @retval true SHA-384 digest computation succeeded.
|
||||
* @retval false SHA-384 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha384_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SHA384_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA512_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SHA-512 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_sha512_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sha512_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sha512_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sha512_free(void *sha512_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed by sha512_context as SHA-512 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sha512_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sha512_context Pointer to SHA-512 context being initialized.
|
||||
*
|
||||
* @retval true SHA-512 context initialization succeeded.
|
||||
* @retval false SHA-512 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sha512_init(void *sha512_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SHA-512 context.
|
||||
*
|
||||
* If sha512_context is NULL, then return false.
|
||||
* If new_sha512_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sha512_context Pointer to SHA-512 context being copied.
|
||||
* @param[out] new_sha512_context Pointer to new SHA-512 context.
|
||||
*
|
||||
* @retval true SHA-512 context copy succeeded.
|
||||
* @retval false SHA-512 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha512_duplicate(const void *sha512_context, void *new_sha512_context);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates SHA-512 context.
|
||||
*
|
||||
* This function performs SHA-512 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.
|
||||
* SHA-512 context should be already correctly initialized by libspdm_sha512_init(), and must not
|
||||
* have been finalized by libspdm_sha512_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sha512_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha512_context Pointer to the SHA-512 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SHA-512 data digest succeeded.
|
||||
* @retval false SHA-512 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sha512_update(void *sha512_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the SHA-512 digest value.
|
||||
*
|
||||
* This function completes SHA-512 hash computation and populates the digest value into
|
||||
* the specified memory. After this function has been called, the SHA-512 context cannot
|
||||
* be used again. SHA-512 context should be already correctly initialized by libspdm_sha512_init(),
|
||||
* and must not have been finalized by libspdm_sha512_final(). Behavior with invalid SHA-512 context
|
||||
* is undefined.
|
||||
*
|
||||
* If sha512_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha512_context Pointer to the SHA-512 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA-512 digest
|
||||
* value (64 bytes).
|
||||
*
|
||||
* @retval true SHA-512 digest computation succeeded.
|
||||
* @retval false SHA-512 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_sha512_final(void *sha512_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SHA-512 message digest of an input data buffer.
|
||||
*
|
||||
* This function performs the SHA-512 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA-512 digest value (64 bytes).
|
||||
*
|
||||
* @retval true SHA-512 digest computation succeeded.
|
||||
* @retval false SHA-512 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha512_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SHA512_SUPPORT */
|
||||
|
||||
/*=====================================================================================
|
||||
* One-way cryptographic hash SHA3 primitives.
|
||||
*=====================================================================================
|
||||
*/
|
||||
#if LIBSPDM_SHA3_256_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SHA3-256 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_sha3_256_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sha3_256_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sha3_256_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sha3_256_free(void *sha3_256_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed by sha3_256_context as SHA3-256 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sha3_256_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sha3_256_context Pointer to SHA3-256 context being initialized.
|
||||
*
|
||||
* @retval true SHA3-256 context initialization succeeded.
|
||||
* @retval false SHA3-256 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_256_init(void *sha3_256_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SHA3-256 context.
|
||||
*
|
||||
* If sha3_256_context is NULL, then return false.
|
||||
* If new_sha3_256_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sha3_256_context Pointer to SHA3-256 context being copied.
|
||||
* @param[out] new_sha3_256_context Pointer to new SHA3-256 context.
|
||||
*
|
||||
* @retval true SHA3-256 context copy succeeded.
|
||||
* @retval false SHA3-256 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha3_256_duplicate(const void *sha3_256_context, void *new_sha3_256_context);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates SHA3-256 context.
|
||||
*
|
||||
* This function performs SHA3-256 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.
|
||||
* SHA3-256 context should be already correctly initialized by libspdm_sha3_256_init(), and must not
|
||||
* have been finalized by libspdm_sha3_256_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sha3_256_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha3_256_context Pointer to the SHA3-256 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SHA3-256 data digest succeeded.
|
||||
* @retval false SHA3-256 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_256_update(void *sha3_256_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the SHA3-256 digest value.
|
||||
*
|
||||
* This function completes SHA3-256 hash computation and populates the digest value into
|
||||
* the specified memory. After this function has been called, the SHA3-512 context cannot
|
||||
* be used again. SHA3-256 context should be already correctly initialized by
|
||||
* libspdm_sha3_256_init(), and must not have been finalized by libspdm_sha3_256_final().
|
||||
* Behavior with invalid SHA3-256 context is undefined.
|
||||
*
|
||||
* If sha3_256_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha3_256_context Pointer to the SHA3-256 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA3-256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true SHA3-256 digest computation succeeded.
|
||||
* @retval false SHA3-256 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_256_final(void *sha3_256_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SHA3-256 message digest of an input data buffer.
|
||||
*
|
||||
* This function performs the SHA3-256 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA3-256 digest value (32 bytes).
|
||||
*
|
||||
* @retval true SHA3-256 digest computation succeeded.
|
||||
* @retval false SHA3-256 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha3_256_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SHA3_256_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_384_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SHA3-384 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_sha3_384_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sha3_384_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sha3_384_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sha3_384_free(void *sha3_384_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed by sha3_384_context as SHA3-384 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sha3_384_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sha3_384_context Pointer to SHA3-384 context being initialized.
|
||||
*
|
||||
* @retval true SHA3-384 context initialization succeeded.
|
||||
* @retval false SHA3-384 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_384_init(void *sha3_384_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SHA3-384 context.
|
||||
*
|
||||
* If sha3_384_context is NULL, then return false.
|
||||
* If new_sha3_384_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sha3_384_context Pointer to SHA3-384 context being copied.
|
||||
* @param[out] new_sha3_384_context Pointer to new SHA3-384 context.
|
||||
*
|
||||
* @retval true SHA3-384 context copy succeeded.
|
||||
* @retval false SHA3-384 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha3_384_duplicate(const void *sha3_384_context, void *new_sha3_384_context);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates SHA3-384 context.
|
||||
*
|
||||
* This function performs SHA3-384 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.
|
||||
* SHA3-384 context should be already correctly initialized by libspdm_sha3_384_init(), and must not
|
||||
* have been finalized by libspdm_sha3_384_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sha3_384_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha3_384_context Pointer to the SHA3-384 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SHA3-384 data digest succeeded.
|
||||
* @retval false SHA3-384 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_384_update(void *sha3_384_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the SHA3-384 digest value.
|
||||
*
|
||||
* This function completes SHA3-384 hash computation and populates the digest value into
|
||||
* the specified memory. After this function has been called, the SHA3-384 context cannot
|
||||
* be used again. SHA3-384 context should be already correctly initialized by
|
||||
* libspdm_sha3_384_init(), and must not have been finalized by libspdm_sha3_384_final().
|
||||
* Behavior with invalid SHA3-384 context is undefined.
|
||||
*
|
||||
* If sha3_384_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha3_384_context Pointer to the SHA3-384 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA3-384 digest
|
||||
* value (48 bytes).
|
||||
*
|
||||
* @retval true SHA3-384 digest computation succeeded.
|
||||
* @retval false SHA3-384 digest computation failed.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_sha3_384_final(void *sha3_384_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SHA3-384 message digest of an input data buffer.
|
||||
*
|
||||
* This function performs the SHA3-384 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA3-384 digest value (48 bytes).
|
||||
*
|
||||
* @retval true SHA3-384 digest computation succeeded.
|
||||
* @retval false SHA3-384 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha3_384_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SHA3_384_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_512_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SHA3-512 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_sha3_512_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sha3_512_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sha3_512_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sha3_512_free(void *sha3_512_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed by sha3_512_context as SHA3-512 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sha3_512_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sha3_512_context Pointer to SHA3-512 context being initialized.
|
||||
*
|
||||
* @retval true SHA3-512 context initialization succeeded.
|
||||
* @retval false SHA3-512 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_512_init(void *sha3_512_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SHA3-512 context.
|
||||
*
|
||||
* If sha3_512_context is NULL, then return false.
|
||||
* If new_sha3_512_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sha3_512_context Pointer to SHA3-512 context being copied.
|
||||
* @param[out] new_sha3_512_context Pointer to new SHA3-512 context.
|
||||
*
|
||||
* @retval true SHA3-512 context copy succeeded.
|
||||
* @retval false SHA3-512 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_sha3_512_duplicate(const void *sha3_512_context, void *new_sha3_512_context);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates SHA3-512 context.
|
||||
*
|
||||
* This function performs SHA3-512 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.
|
||||
* SHA3-512 context should be already correctly initialized by libspdm_sha3_512_init(), and must not
|
||||
* have been finalized by libspdm_sha3_512_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sha3_512_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha3_512_context Pointer to the SHA3-512 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SHA3-512 data digest succeeded.
|
||||
* @retval false SHA3-512 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_512_update(void *sha3_512_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the SHA3-512 digest value.
|
||||
*
|
||||
* This function completes SHA3-512 hash computation and populates the digest value into
|
||||
* the specified memory. After this function has been called, the SHA3-512 context cannot
|
||||
* be used again. SHA3-512 context should be already correctly initialized by
|
||||
* libspdm_sha3_512_init(), and must not have been finalized by libspdm_sha3_512_final().
|
||||
* Behavior with invalid SHA3-512 context is undefined.
|
||||
*
|
||||
* If sha3_512_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sha3_512_context Pointer to the SHA3-512 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA3-512 digest
|
||||
* value (64 bytes).
|
||||
*
|
||||
* @retval true SHA3-512 digest computation succeeded.
|
||||
* @retval false SHA3-512 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_sha3_512_final(void *sha3_512_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SHA3-512 message digest of an input data buffer.
|
||||
*
|
||||
* This function performs the SHA3-512 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SHA3-512 digest value (64 bytes).
|
||||
*
|
||||
* @retval true SHA3-512 digest computation succeeded.
|
||||
* @retval false SHA3-512 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sha3_512_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SHA3_512_SUPPORT */
|
||||
|
||||
/*=====================================================================================
|
||||
* One-Way Cryptographic hash SM3 Primitives
|
||||
*=====================================================================================
|
||||
*/
|
||||
|
||||
#if LIBSPDM_SM3_256_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HASH_CTX context for subsequent SM3-256 use.
|
||||
*
|
||||
* @return Pointer to the HASH_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_sm3_256_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sm3_256_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HASH_CTX context.
|
||||
*
|
||||
* @param[in] sm3_context Pointer to the HASH_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_sm3_256_free(void *sm3_context);
|
||||
|
||||
/**
|
||||
* Initializes user-supplied memory pointed by sm3_context as SM3 hash context for
|
||||
* subsequent use.
|
||||
*
|
||||
* If sm3_context is NULL, then return false.
|
||||
*
|
||||
* @param[out] sm3_context Pointer to SM3 context being initialized.
|
||||
*
|
||||
* @retval true SM3 context initialization succeeded.
|
||||
* @retval false SM3 context initialization failed.
|
||||
**/
|
||||
extern bool libspdm_sm3_256_init(void *sm3_context);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing SM3 context.
|
||||
*
|
||||
* If sm3_context is NULL, then return false.
|
||||
* If new_sm3_context is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] sm3_context Pointer to SM3 context being copied.
|
||||
* @param[out] new_sm3_context Pointer to new SM3 context.
|
||||
*
|
||||
* @retval true SM3 context copy succeeded.
|
||||
* @retval false SM3 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_sm3_256_duplicate(const void *sm3_context, void *new_sm3_context);
|
||||
|
||||
/**
|
||||
* 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 sm3_init(), and should not be finalized
|
||||
* by sm3_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If sm3_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sm3_context Pointer to the SM3 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be hashed.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true SM3 data digest succeeded.
|
||||
* @retval false SM3 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_sm3_256_update(void *sm3_context, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* 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 sm3_init(), and should not
|
||||
* be finalized by sm3_final(). Behavior with invalid SM3 context is undefined.
|
||||
*
|
||||
* If sm3_context is NULL, then return false.
|
||||
* If hash_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sm3_context Pointer to the SM3 context.
|
||||
* @param[out] hash_value Pointer to a buffer that receives the SM3 digest value (32 bytes).
|
||||
*
|
||||
* @retval true SM3 digest computation succeeded.
|
||||
* @retval false SM3 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_sm3_256_final(void *sm3_context, uint8_t *hash_value);
|
||||
|
||||
/**
|
||||
* Computes the SM3 message digest of an 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] data_size Size of data buffer in bytes.
|
||||
* @param[out] hash_value 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.
|
||||
**/
|
||||
extern bool libspdm_sm3_256_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
|
||||
#endif /* LIBSPDM_SM3_256_SUPPORT */
|
||||
|
||||
#endif /* CRYPTLIB_HASH_H */
|
||||
@@ -1,266 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_HKDF_H
|
||||
#define CRYPTLIB_HKDF_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Key Derivation Function Primitives
|
||||
*=====================================================================================*/
|
||||
|
||||
#if LIBSPDM_SHA256_SUPPORT
|
||||
/**
|
||||
* Derive SHA-256 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive prk value.
|
||||
* @param[in] prk_out_size Size of prk bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha256_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SHA256 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha256_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SHA256_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA384_SUPPORT
|
||||
/**
|
||||
* Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] prk_out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha384_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SHA384 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha384_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SHA384_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA512_SUPPORT
|
||||
/**
|
||||
* Derive SHA512 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] prk_out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha512_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SHA512 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha512_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SHA512_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_256_SUPPORT
|
||||
/**
|
||||
* Derive SHA3_256 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] prk_out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha3_256_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SHA3_256 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha3_256_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SHA3_256_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_384_SUPPORT
|
||||
/**
|
||||
* Derive SHA3_384 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] prk_out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha3_384_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SHA3_384 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha3_384_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SHA3_384_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_512_SUPPORT
|
||||
/**
|
||||
* Derive SHA3_512 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] prk_out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha3_512_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SHA3_512 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sha3_512_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SHA3_512_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SM3_256_SUPPORT
|
||||
/**
|
||||
* Derive SM3_256 HMAC-based Extract key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[in] salt Pointer to the salt value.
|
||||
* @param[in] salt_size Salt size in bytes.
|
||||
* @param[out] prk_out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] prk_out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sm3_256_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size);
|
||||
|
||||
/**
|
||||
* Derive SM3_256 HMAC-based Expand key Derivation Function (HKDF).
|
||||
*
|
||||
* @param[in] prk Pointer to the user-supplied key.
|
||||
* @param[in] prk_size Key size in bytes.
|
||||
* @param[in] info Pointer to the application specific info.
|
||||
* @param[in] info_size Info size in bytes.
|
||||
* @param[out] out Pointer to buffer to receive hkdf value.
|
||||
* @param[in] out_size Size of hkdf bytes to generate.
|
||||
*
|
||||
* @retval true Hkdf generated successfully.
|
||||
* @retval false Hkdf generation failed.
|
||||
**/
|
||||
extern bool libspdm_hkdf_sm3_256_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
#endif /* LIBSPDM_SM3_256_SUPPORT */
|
||||
|
||||
#endif /* CRYPTLIB_HKDF_H */
|
||||
@@ -1,833 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_MAC_H
|
||||
#define CRYPTLIB_MAC_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Message Authentication Code (MAC) Primitives
|
||||
*=====================================================================================
|
||||
*/
|
||||
|
||||
#if LIBSPDM_SHA256_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sha256_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sha256_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sha256_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sha256_free(void *hmac_sha256_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sha256_update().
|
||||
*
|
||||
* If hmac_sha256_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[out] hmac_sha256_ctx Pointer to HMAC-SHA256 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha256_set_key(void *hmac_sha256_ctx, const uint8_t *key, size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SHA256 context.
|
||||
*
|
||||
* If hmac_sha256_ctx is NULL, then return false.
|
||||
* If new_hmac_sha256_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] hmac_sha256_ctx Pointer to HMAC-SHA256 context being copied.
|
||||
* @param[out] new_hmac_sha256_ctx Pointer to new HMAC-SHA256 context.
|
||||
*
|
||||
* @retval true HMAC-SHA256 context copy succeeded.
|
||||
* @retval false HMAC-SHA256 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha256_duplicate(const void *hmac_sha256_ctx, void *new_hmac_sha256_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SHA256 context.
|
||||
*
|
||||
* This function performs HMAC-SHA256 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.
|
||||
* HMAC-SHA256 context should be initialized by libspdm_hmac_sha256_new(), and should not be
|
||||
* finalized by libspdm_hmac_sha256_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sha256_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha256_ctx Pointer to the HMAC-SHA256 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SHA256 data digest succeeded.
|
||||
* @retval false HMAC-SHA256 data digest failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha256_update(void *hmac_sha256_ctx, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SHA256 digest value.
|
||||
*
|
||||
* This function completes HMAC-SHA256 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SHA256 context cannot
|
||||
* be used again. HMAC-SHA256 context should be initialized by libspdm_hmac_sha256_new(), and should
|
||||
* not be finalized by libspdm_hmac_sha256_final(). Behavior with invalid HMAC-SHA256 context is
|
||||
* undefined.
|
||||
*
|
||||
* If hmac_sha256_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha256_ctx Pointer to the HMAC-SHA256 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA256 digest computation succeeded.
|
||||
* @retval false HMAC-SHA256 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha256_final(void *hmac_sha256_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SHA256 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SHA256 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA256 digest computation succeeded.
|
||||
* @retval false HMAC-SHA256 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha256_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SHA256_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA384_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sha384_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sha384_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sha384_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sha384_free(void *hmac_sha384_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sha384_update().
|
||||
*
|
||||
* If hmac_sha384_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[out] hmac_sha384_ctx Pointer to HMAC-SHA384 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha384_set_key(void *hmac_sha384_ctx, const uint8_t *key, size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SHA384 context.
|
||||
*
|
||||
* If hmac_sha384_ctx is NULL, then return false.
|
||||
* If new_hmac_sha384_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] hmac_sha384_ctx Pointer to HMAC-SHA384 context being copied.
|
||||
* @param[out] new_hmac_sha384_ctx Pointer to new HMAC-SHA384 context.
|
||||
*
|
||||
* @retval true HMAC-SHA384 context copy succeeded.
|
||||
* @retval false HMAC-SHA384 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha384_duplicate(const void *hmac_sha384_ctx, void *new_hmac_sha384_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SHA384 context.
|
||||
*
|
||||
* This function performs HMAC-SHA384 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.
|
||||
* HMAC-SHA384 context should be initialized by libspdm_hmac_sha384_new(), and should not be
|
||||
* finalized by libspdm_hmac_sha384_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sha384_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha384_ctx Pointer to the HMAC-SHA384 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SHA384 data digest succeeded.
|
||||
* @retval false HMAC-SHA384 data digest failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha384_update(void *hmac_sha384_ctx, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SHA384 digest value.
|
||||
*
|
||||
* This function completes HMAC-SHA384 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SHA384 context cannot
|
||||
* be used again. HMAC-SHA384 context should be initialized by libspdm_hmac_sha384_new(), and should
|
||||
* not be finalized by libspdm_hmac_sha384_final(). Behavior with invalid HMAC-SHA384 context is
|
||||
* undefined.
|
||||
*
|
||||
* If hmac_sha384_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha384_ctx Pointer to the HMAC-SHA384 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA384 digest
|
||||
* value (48 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA384 digest computation succeeded.
|
||||
* @retval false HMAC-SHA384 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha384_final(void *hmac_sha384_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SHA384 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SHA384 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA384 digest
|
||||
* value (48 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA384 digest computation succeeded.
|
||||
* @retval false HMAC-SHA384 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha384_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SHA384_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA512_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA512 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sha512_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sha512_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sha512_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sha512_free(void *hmac_sha512_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sha512_update().
|
||||
*
|
||||
* If hmac_sha512_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[out] hmac_sha512_ctx Pointer to HMAC-SHA512 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha512_set_key(void *hmac_sha512_ctx, const uint8_t *key, size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SHA512 context.
|
||||
*
|
||||
* If hmac_sha512_ctx is NULL, then return false.
|
||||
* If new_hmac_sha512_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] hmac_sha512_ctx Pointer to HMAC-SHA512 context being copied.
|
||||
* @param[out] new_hmac_sha512_ctx Pointer to new HMAC-SHA512 context.
|
||||
*
|
||||
* @retval true HMAC-SHA512 context copy succeeded.
|
||||
* @retval false HMAC-SHA512 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha512_duplicate(const void *hmac_sha512_ctx, void *new_hmac_sha512_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SHA512 context.
|
||||
*
|
||||
* This function performs HMAC-SHA512 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.
|
||||
* HMAC-SHA512 context should be initialized by libspdm_hmac_sha512_new(), and should not be
|
||||
* finalized by libspdm_hmac_sha512_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sha512_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha512_ctx Pointer to the HMAC-SHA512 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SHA512 data digest succeeded.
|
||||
* @retval false HMAC-SHA512 data digest failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha512_update(void *hmac_sha512_ctx, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SHA512 digest value.
|
||||
*
|
||||
* This function completes HMAC-SHA512 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SHA512 context cannot
|
||||
* be used again. HMAC-SHA512 context should be initialized by libspdm_hmac_sha512_new(), and should
|
||||
* not be finalized by libspdm_hmac_sha512_final(). Behavior with invalid HMAC-SHA512 context is
|
||||
* undefined.
|
||||
*
|
||||
* If hmac_sha512_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha512_ctx Pointer to the HMAC-SHA512 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA512 digest
|
||||
* value (64 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA512 digest computation succeeded.
|
||||
* @retval false HMAC-SHA512 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha512_final(void *hmac_sha512_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SHA512 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SHA512 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA512 digest
|
||||
* value (64 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA512 digest computation succeeded.
|
||||
* @retval false HMAC-SHA512 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_hmac_sha512_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SHA512_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_256_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA3-256 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sha3_256_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sha3_256_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sha3_256_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sha3_256_free(void *hmac_sha3_256_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sha3_256_update().
|
||||
*
|
||||
* If hmac_sha3_256_ctx is NULL, then return false.
|
||||
*
|
||||
* @param[out] hmac_sha3_256_ctx Pointer to HMAC-SHA3-256 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_256_set_key(void *hmac_sha3_256_ctx,
|
||||
const uint8_t *key,
|
||||
size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SHA3-256 context.
|
||||
*
|
||||
* If hmac_sha3_256_ctx is NULL, then return false.
|
||||
* If new_hmac_sha3_256_ctx is NULL, then return false.
|
||||
*
|
||||
* @param[in] hmac_sha3_256_ctx Pointer to HMAC-SHA3-256 context being copied.
|
||||
* @param[out] new_hmac_sha3_256_ctx Pointer to new HMAC-SHA3-256 context.
|
||||
*
|
||||
* @retval true HMAC-SHA3-256 context copy succeeded.
|
||||
* @retval false HMAC-SHA3-256 context copy failed.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_256_duplicate(const void *hmac_sha3_256_ctx,
|
||||
void *new_hmac_sha3_256_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SHA3-256 context.
|
||||
*
|
||||
* This function performs HMAC-SHA3-256 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.
|
||||
* HMAC-SHA3-256 context should be initialized by libspdm_hmac_sha3_256_new(), and should not be
|
||||
* finalized by libspdm_hmac_sha3_256_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sha3_256_ctx is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha3_256_ctx Pointer to the HMAC-SHA3-256 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SHA3-256 data digest succeeded.
|
||||
* @retval false HMAC-SHA3-256 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_256_update(void *hmac_sha3_256_ctx,
|
||||
const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SHA3-256 digest value.
|
||||
*
|
||||
* This function completes HMAC-SHA3-256 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SHA3-256 context cannot
|
||||
* be used again. HMAC-SHA3-256 context should be initialized by libspdm_hmac_sha3_256_new(), and
|
||||
* should not be finalized by libspdm_hmac_sha3_256_final(). Behavior with invalid HMAC-SHA3-256
|
||||
* context is undefined.
|
||||
*
|
||||
* If hmac_sha3_256_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha3_256_ctx Pointer to the HMAC-SHA3-256 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA3-256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA3-256 digest computation succeeded.
|
||||
* @retval false HMAC-SHA3-256 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_256_final(void *hmac_sha3_256_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SHA3-256 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SHA3-256 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA3-256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA3-256 digest computation succeeded.
|
||||
* @retval false HMAC-SHA3-256 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_256_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SHA3_256_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_384_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA3-384 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sha3_384_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sha3_384_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sha3_384_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sha3_384_free(void *hmac_sha3_384_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sha3_384_update().
|
||||
*
|
||||
* If hmac_sha3_384_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[out] hmac_sha3_384_ctx Pointer to HMAC-SHA3-384 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_384_set_key(void *hmac_sha3_384_ctx,
|
||||
const uint8_t *key,
|
||||
size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SHA3-384 context.
|
||||
*
|
||||
* If hmac_sha3_384_ctx is NULL, then return false.
|
||||
* If new_hmac_sha3_384_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] hmac_sha3_384_ctx Pointer to HMAC-SHA3-384 context being copied.
|
||||
* @param[out] new_hmac_sha3_384_ctx Pointer to new HMAC-SHA3-384 context.
|
||||
*
|
||||
* @retval true HMAC-SHA3-384 context copy succeeded.
|
||||
* @retval false HMAC-SHA3-384 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_384_duplicate(const void *hmac_sha3_384_ctx,
|
||||
void *new_hmac_sha3_384_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SHA3-384 context.
|
||||
*
|
||||
* This function performs HMAC-SHA3-384 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.
|
||||
* HMAC-SHA3-384 context should be initialized by libspdm_hmac_sha3_384_new(), and should not be
|
||||
* finalized by libspdm_hmac_sha3_384_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sha3_384_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha3_384_ctx Pointer to the HMAC-SHA3-384 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SHA3-384 data digest succeeded.
|
||||
* @retval false HMAC-SHA3-384 data digest failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_384_update(void *hmac_sha3_384_ctx, const void *data,
|
||||
size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SHA3-384 digest value.
|
||||
*
|
||||
* This function completes HMAC-SHA3-384 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SHA3-384 context cannot
|
||||
* be used again. HMAC-SHA3-384 context should be initialized by libspdm_hmac_sha3_384_new(), and
|
||||
* should not be finalized by libspdm_hmac_sha3_384_final(). Behavior with invalid HMAC-SHA3-384
|
||||
* context is undefined.
|
||||
*
|
||||
* If hmac_sha3_384_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha3_384_ctx Pointer to the HMAC-SHA3-384 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA3-384 digest
|
||||
* value (48 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA3-384 digest computation succeeded.
|
||||
* @retval false HMAC-SHA3-384 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_384_final(void *hmac_sha3_384_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SHA3-384 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SHA3-384 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA3-384 digest
|
||||
* value (48 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA3-384 digest computation succeeded.
|
||||
* @retval false HMAC-SHA3-384 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_384_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SHA3_384_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SHA3_512_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA3-512 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sha3_512_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sha3_512_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sha3_512_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sha3_512_free(void *hmac_sha3_512_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sha3_512_update().
|
||||
*
|
||||
* If hmac_sha3_512_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[out] hmac_sha3_512_ctx Pointer to HMAC-SHA3-512 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_512_set_key(void *hmac_sha3_512_ctx,
|
||||
const uint8_t *key,
|
||||
size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SHA3-512 context.
|
||||
*
|
||||
* If hmac_sha3_512_ctx is NULL, then return false.
|
||||
* If new_hmac_sha3_512_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] hmac_sha3_512_ctx Pointer to HMAC-SHA3-512 context being copied.
|
||||
* @param[out] new_hmac_sha3_512_ctx Pointer to new HMAC-SHA3-512 context.
|
||||
*
|
||||
* @retval true HMAC-SHA3-512 context copy succeeded.
|
||||
* @retval false HMAC-SHA3-512 context copy failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_512_duplicate(const void *hmac_sha3_512_ctx,
|
||||
void *new_hmac_sha3_512_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SHA3-512 context.
|
||||
*
|
||||
* This function performs HMAC-SHA3-512 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.
|
||||
* HMAC-SHA3-512 context should be initialized by libspdm_hmac_sha3_512_new(), and should not be
|
||||
* finalized by libspdm_hmac_sha3_512_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sha3_512_ctx is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha3_512_ctx Pointer to the HMAC-SHA3-512 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SHA3-512 data digest succeeded.
|
||||
* @retval false HMAC-SHA3-512 data digest failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_512_update(void *hmac_sha3_512_ctx,
|
||||
const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SHA3-512 digest value.
|
||||
*
|
||||
* This function completes HMAC-SHA3-512 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SHA3-512 context cannot
|
||||
* be used again. HMAC-SHA3-512 context should be initialized by libspdm_hmac_sha3_512_new(), and
|
||||
* should not be finalized by libspdm_hmac_sha3_512_final(). Behavior with invalid HMAC-SHA3-512
|
||||
* context is undefined.
|
||||
*
|
||||
* If hmac_sha3_512_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sha3_512_ctx Pointer to the HMAC-SHA3-512 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA3-512 digest
|
||||
* value (64 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA3-512 digest computation succeeded.
|
||||
* @retval false HMAC-SHA3-512 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_512_final(void *hmac_sha3_512_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SHA3-512 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SHA3-512 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SHA3-512 digest
|
||||
* value (64 bytes).
|
||||
*
|
||||
* @retval true HMAC-SHA3-512 digest computation succeeded.
|
||||
* @retval false HMAC-SHA3-512 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sha3_512_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SHA3_512_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SM3_256_SUPPORT
|
||||
/**
|
||||
* Allocates and initializes one HMAC_CTX context for subsequent HMAC-SM3-256 use.
|
||||
*
|
||||
* @return Pointer to the HMAC_CTX context that has been initialized.
|
||||
* If the allocations fails, libspdm_hmac_sm3_256_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_hmac_sm3_256_new(void);
|
||||
|
||||
/**
|
||||
* Release the specified HMAC_CTX context.
|
||||
*
|
||||
* @param[in] hmac_sm3_256_ctx Pointer to the HMAC_CTX context to be released.
|
||||
**/
|
||||
extern void libspdm_hmac_sm3_256_free(void *hmac_sm3_256_ctx);
|
||||
|
||||
/**
|
||||
* Set user-supplied key for subsequent use. It must be done before any
|
||||
* calling to libspdm_hmac_sm3_256_update().
|
||||
*
|
||||
* If hmac_sm3_256_ctx is NULL, then return false.
|
||||
*
|
||||
* @param[out] hmac_sm3_256_ctx Pointer to HMAC-SM3-256 context.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
*
|
||||
* @retval true The key is set successfully.
|
||||
* @retval false The key is set unsuccessfully.
|
||||
**/
|
||||
extern bool libspdm_hmac_sm3_256_set_key(void *hmac_sm3_256_ctx,
|
||||
const uint8_t *key, size_t key_size);
|
||||
|
||||
/**
|
||||
* Makes a copy of an existing HMAC-SM3-256 context.
|
||||
*
|
||||
* If hmac_sm3_256_ctx is NULL, then return false.
|
||||
* If new_hmac_sm3_256_ctx is NULL, then return false.
|
||||
*
|
||||
* @param[in] hmac_sm3_256_ctx Pointer to HMAC-SM3-256 context being copied.
|
||||
* @param[out] new_hmac_sm3_256_ctx Pointer to new HMAC-SM3-256 context.
|
||||
*
|
||||
* @retval true HMAC-SM3-256 context copy succeeded.
|
||||
* @retval false HMAC-SM3-256 context copy failed.
|
||||
**/
|
||||
extern bool libspdm_hmac_sm3_256_duplicate(const void *hmac_sm3_256_ctx,
|
||||
void *new_hmac_sm3_256_ctx);
|
||||
|
||||
/**
|
||||
* Digests the input data and updates HMAC-SM3-256 context.
|
||||
*
|
||||
* This function performs HMAC-SM3-256 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.
|
||||
* HMAC-SM3-256 context should be initialized by libspdm_hmac_sm3_256_new(), and should not be
|
||||
* finalized by libspdm_hmac_sm3_256_final(). Behavior with invalid context is undefined.
|
||||
*
|
||||
* If hmac_sm3_256_ctx is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sm3_256_ctx Pointer to the HMAC-SM3-256 context.
|
||||
* @param[in] data Pointer to the buffer containing the data to be digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
*
|
||||
* @retval true HMAC-SM3-256 data digest succeeded.
|
||||
* @retval false HMAC-SM3-256 data digest failed.
|
||||
**/
|
||||
extern bool libspdm_hmac_sm3_256_update(void *hmac_sm3_256_ctx, const void *data, size_t data_size);
|
||||
|
||||
/**
|
||||
* Completes computation of the HMAC-SM3-256 digest value.
|
||||
*
|
||||
* This function completes HMAC-SM3-256 hash computation and retrieves the digest value into
|
||||
* the specified memory. After this function has been called, the HMAC-SM3-256 context cannot
|
||||
* be used again. HMAC-SM3-256 context should be initialized by libspdm_hmac_sm3_256_new(), and
|
||||
* should not be finalized by libspdm_hmac_sm3_256_final(). Behavior with invalid HMAC-SM3-256
|
||||
* context is undefined.
|
||||
*
|
||||
* If hmac_sm3_256_ctx is NULL, then return false.
|
||||
* If hmac_value is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] hmac_sm3_256_ctx Pointer to the HMAC-SM3-256 context.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SM3-256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true HMAC-SM3-256 digest computation succeeded.
|
||||
* @retval false HMAC-SM3-256 digest computation failed.
|
||||
**/
|
||||
extern bool libspdm_hmac_sm3_256_final(void *hmac_sm3_256_ctx, uint8_t *hmac_value);
|
||||
|
||||
/**
|
||||
* Computes the HMAC-SM3-256 digest of a input data buffer.
|
||||
*
|
||||
* This function performs the HMAC-SM3-256 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 digested.
|
||||
* @param[in] data_size Size of data buffer in bytes.
|
||||
* @param[in] key Pointer to the user-supplied key.
|
||||
* @param[in] key_size Key size in bytes.
|
||||
* @param[out] hmac_value Pointer to a buffer that receives the HMAC-SM3-256 digest
|
||||
* value (32 bytes).
|
||||
*
|
||||
* @retval true HMAC-SM3-256 digest computation succeeded.
|
||||
* @retval false HMAC-SM3-256 digest computation failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_hmac_sm3_256_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value);
|
||||
#endif /* LIBSPDM_SM3_256_SUPPORT */
|
||||
|
||||
#endif /* CRYPTLIB_MAC_H */
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_RNG_H
|
||||
#define CRYPTLIB_RNG_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Random Number Generation Primitive
|
||||
*=====================================================================================*/
|
||||
|
||||
/**
|
||||
* Generates a random byte stream of the specified size. If initialization, testing, or seeding of
|
||||
* the (pseudo)random number generator is required it should be done before this function is called.
|
||||
*
|
||||
* If output is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[out] output Pointer to buffer to receive random value.
|
||||
* @param[in] size Size of random bytes to generate.
|
||||
*
|
||||
* @retval true Random byte stream generated successfully.
|
||||
* @retval false Generation of random byte stream failed.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_random_bytes(uint8_t *output, size_t size);
|
||||
|
||||
#endif /* CRYPTLIB_RNG_H */
|
||||
@@ -1,274 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_RSA_H
|
||||
#define CRYPTLIB_RSA_H
|
||||
|
||||
/*=====================================================================================
|
||||
* RSA Cryptography Primitives
|
||||
*=====================================================================================
|
||||
*/
|
||||
|
||||
#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
|
||||
/* RSA key Tags Definition used in libspdm_rsa_set_key() function for key component
|
||||
* identification.
|
||||
*/
|
||||
typedef enum {
|
||||
LIBSPDM_RSA_KEY_N, /*< RSA public Modulus (N)*/
|
||||
LIBSPDM_RSA_KEY_E, /*< RSA public exponent (e)*/
|
||||
LIBSPDM_RSA_KEY_D, /*< RSA Private exponent (d)*/
|
||||
LIBSPDM_RSA_KEY_P, /*< RSA secret prime factor of Modulus (p)*/
|
||||
LIBSPDM_RSA_KEY_Q, /*< RSA secret prime factor of Modules (q)*/
|
||||
LIBSPDM_RSA_KEY_DP, /*< p's CRT exponent (== d mod (p - 1))*/
|
||||
LIBSPDM_RSA_KEY_DQ, /*< q's CRT exponent (== d mod (q - 1))*/
|
||||
LIBSPDM_RSA_KEY_Q_INV /*< The CRT coefficient (== 1/q mod p)*/
|
||||
} libspdm_rsa_key_tag_t;
|
||||
|
||||
/**
|
||||
* Allocates and initializes one RSA context for subsequent use.
|
||||
*
|
||||
* @return Pointer to the RSA context that has been initialized.
|
||||
* If the allocations fails, libspdm_rsa_new() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_rsa_new(void);
|
||||
|
||||
/**
|
||||
* Generates RSA context from DER-encoded public key data.
|
||||
*
|
||||
* The public key is ASN.1 DER-encoded as RFC7250 describes,
|
||||
* namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
|
||||
*
|
||||
* @param[in] der_data Pointer to the DER-encoded public key data.
|
||||
* @param[in] der_size Size of the DER-encoded public key data in bytes.
|
||||
* @param[out] rsa_context Pointer to newly generated RSA context which contains the
|
||||
* RSA public key component.
|
||||
* Use libspdm_rsa_free() function to free the resource.
|
||||
*
|
||||
* If der_data is NULL, then return false.
|
||||
* If rsa_context is NULL, then return false.
|
||||
*
|
||||
* @retval true RSA context was generated successfully.
|
||||
* @retval false Invalid DER public key data.
|
||||
**/
|
||||
extern bool libspdm_rsa_get_public_key_from_der(const uint8_t *der_data,
|
||||
size_t der_size,
|
||||
void **rsa_context);
|
||||
|
||||
/**
|
||||
* Release the specified RSA context.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to the RSA context to be released.
|
||||
**/
|
||||
extern void libspdm_rsa_free(void *rsa_context);
|
||||
|
||||
/**
|
||||
* Sets the tag-designated key component into the established RSA context.
|
||||
*
|
||||
* This function sets the tag-designated RSA key component into the established
|
||||
* RSA context from the user-specified non-negative integer (octet string format
|
||||
* represented in RSA PKCS#1).
|
||||
* If big_number is NULL, then the specified key component in RSA context is cleared.
|
||||
* If rsa_context is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] rsa_context Pointer to RSA context being set.
|
||||
* @param[in] key_tag tag of RSA key component being set.
|
||||
* @param[in] big_number Pointer to octet integer buffer.
|
||||
* If NULL, then the specified key component in RSA
|
||||
* context is cleared.
|
||||
* @param[in] bn_size Size of big number buffer in bytes.
|
||||
* If big_number is NULL, then it is ignored.
|
||||
*
|
||||
* @retval true RSA key component was set successfully.
|
||||
* @retval false Invalid RSA key component tag.
|
||||
**/
|
||||
extern bool libspdm_rsa_set_key(void *rsa_context, const libspdm_rsa_key_tag_t key_tag,
|
||||
const uint8_t *big_number, size_t bn_size);
|
||||
|
||||
#endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
|
||||
|
||||
#if LIBSPDM_RSA_SSA_SUPPORT
|
||||
/**
|
||||
* 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 sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256,
|
||||
* SHA3_384, SHA3_512.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
* If this interface is not supported, then return false.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be signed.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
|
||||
* @param[in, out] sig_size 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 sig_size is too small.
|
||||
* @retval false This interface is not supported.
|
||||
**/
|
||||
extern bool libspdm_rsa_pkcs1_sign_with_nid(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash,
|
||||
size_t hash_size, uint8_t *signature,
|
||||
size_t *sig_size);
|
||||
|
||||
/**
|
||||
* Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in RSA PKCS#1.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If signature is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256,
|
||||
* SHA3_384, SHA3_512.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature verification.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be checked.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[in] signature Pointer to RSA PKCS1-v1_5 signature to be verified.
|
||||
* @param[in] sig_size Size of signature in bytes.
|
||||
*
|
||||
* @retval true Valid signature encoded in PKCS1-v1_5.
|
||||
* @retval false Invalid signature or invalid RSA context.
|
||||
**/
|
||||
extern bool libspdm_rsa_pkcs1_verify_with_nid(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash,
|
||||
size_t hash_size, const uint8_t *signature,
|
||||
size_t sig_size);
|
||||
#endif /* LIBSPDM_RSA_SSA_SUPPORT */
|
||||
|
||||
#if LIBSPDM_RSA_PSS_SUPPORT
|
||||
/**
|
||||
* 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 RSA PKCS#1 v2.2.
|
||||
*
|
||||
* The salt length is same as digest length.
|
||||
*
|
||||
* If the signature buffer is too small to hold the contents of signature, false
|
||||
* is returned and sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384,
|
||||
* SHA3_512.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be signed.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive RSA-SSA PSS signature.
|
||||
* @param[in, out] sig_size 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 RSA-SSA PSS.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
**/
|
||||
extern bool libspdm_rsa_pss_sign(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size);
|
||||
|
||||
/**
|
||||
* Verifies the RSA-SSA signature with EMSA-PSS encoding scheme defined in
|
||||
* RSA PKCS#1 v2.2.
|
||||
*
|
||||
* The salt length is same as digest length.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If signature is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384,
|
||||
* SHA3_512.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature verification.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be checked.
|
||||
* @param[in] hash_size Size of the message hash in bytes.
|
||||
* @param[in] signature Pointer to RSA-SSA PSS signature to be verified.
|
||||
* @param[in] sig_size Size of signature in bytes.
|
||||
*
|
||||
* @retval true Valid signature encoded in RSA-SSA PSS.
|
||||
* @retval false Invalid signature or invalid RSA context.
|
||||
**/
|
||||
extern bool libspdm_rsa_pss_verify(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
|
||||
#if LIBSPDM_FIPS_MODE
|
||||
/**
|
||||
* Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme for FIPS test.
|
||||
*
|
||||
* This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
|
||||
* RSA PKCS#1 v2.2 for FIPS test.
|
||||
*
|
||||
* The salt length is zero.
|
||||
*
|
||||
* If the signature buffer is too small to hold the contents of signature, false
|
||||
* is returned and sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be signed.
|
||||
* @param[in] hash_size size of the message hash in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive RSA-SSA PSS signature.
|
||||
* @param[in, out] sig_size 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 RSA-SSA PSS.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_rsa_pss_sign_fips(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size);
|
||||
|
||||
/**
|
||||
* Verifies the RSA-SSA signature with EMSA-PSS encoding scheme defined in
|
||||
* RSA PKCS#1 v2.2 for FIPS test.
|
||||
*
|
||||
* The salt length is zero.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If signature is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature verification.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be checked.
|
||||
* @param[in] hash_size size of the message hash in bytes.
|
||||
* @param[in] signature Pointer to RSA-SSA PSS signature to be verified.
|
||||
* @param[in] sig_size size of signature in bytes.
|
||||
*
|
||||
* @retval true Valid signature encoded in RSA-SSA PSS.
|
||||
* @retval false Invalid signature or invalid RSA context.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_rsa_pss_verify_fips(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
#endif /*LIBSPDM_FIPS_MODE*/
|
||||
|
||||
#endif /* LIBSPDM_RSA_PSS_SUPPORT */
|
||||
#endif /* CRYPTLIB_RSA_H */
|
||||
@@ -1,217 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_SM2_H
|
||||
#define CRYPTLIB_SM2_H
|
||||
|
||||
/*=====================================================================================
|
||||
* Shang-Mi2 Primitives
|
||||
*=====================================================================================*/
|
||||
|
||||
#if LIBSPDM_SM2_DSA_SUPPORT
|
||||
/**
|
||||
* Allocates and Initializes one Shang-Mi2 context for subsequent use.
|
||||
*
|
||||
* @param nid cipher NID
|
||||
*
|
||||
* @return Pointer to the Shang-Mi2 context that has been initialized.
|
||||
* If the allocations fails, sm2_new_by_nid() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sm2_dsa_new_by_nid(size_t nid);
|
||||
|
||||
/**
|
||||
* Generates Shang-Mi2 context from DER-encoded public key data.
|
||||
*
|
||||
* The public key is ASN.1 DER-encoded as RFC7250 describes,
|
||||
* namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
|
||||
*
|
||||
* @param[in] der_data Pointer to the DER-encoded public key data.
|
||||
* @param[in] der_size Size of the DER-encoded public key data in bytes.
|
||||
* @param[out] sm2_context Pointer to newly generated SM2 context which contains the
|
||||
* SM2 public key component.
|
||||
* Use libspdm_sm2_free() function to free the resource.
|
||||
*
|
||||
* If der_data is NULL, then return false.
|
||||
* If sm2_context is NULL, then return false.
|
||||
*
|
||||
* @retval true SM2 context was generated successfully.
|
||||
* @retval false Invalid DER public key data.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_sm2_get_public_key_from_der(const uint8_t *der_data,
|
||||
size_t der_size,
|
||||
void **sm2_context);
|
||||
|
||||
/**
|
||||
* Release the specified sm2 context.
|
||||
*
|
||||
* @param[in] sm2_context Pointer to the sm2 context to be released.
|
||||
**/
|
||||
extern void libspdm_sm2_dsa_free(void *sm2_context);
|
||||
|
||||
/**
|
||||
* Carries out the SM2 signature, based upon GB/T 32918.2-2016: SM2 - Part2.
|
||||
*
|
||||
* This function carries out the SM2 signature.
|
||||
* If the signature buffer is too small to hold the contents of signature, false
|
||||
* is returned and sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If sm2_context is NULL, then return false.
|
||||
* If message is NULL, then return false.
|
||||
* hash_nid must be SM3_256.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
*
|
||||
* The id_a_size must be smaller than 2^16-1.
|
||||
* The sig_size is 64. first 32-byte is R, second 32-byte is S.
|
||||
*
|
||||
* @param[in] sm2_context Pointer to sm2 context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] id_a The ID-A of the signing context.
|
||||
* @param[in] id_a_size Size of ID-A signing context.
|
||||
* @param[in] message Pointer to octet message to be signed (before hash).
|
||||
* @param[in] size Size of the message in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive SM2 signature.
|
||||
* @param[in, out] sig_size 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 SM2.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
**/
|
||||
extern bool libspdm_sm2_dsa_sign(const void *sm2_context, size_t hash_nid,
|
||||
const uint8_t *id_a, size_t id_a_size,
|
||||
const uint8_t *message, size_t size,
|
||||
uint8_t *signature, size_t *sig_size);
|
||||
|
||||
/**
|
||||
* Verifies the SM2 signature, based upon GB/T 32918.2-2016: SM2 - Part2.
|
||||
*
|
||||
* If sm2_context is NULL, then return false.
|
||||
* If message is NULL, then return false.
|
||||
* If signature is NULL, then return false.
|
||||
* hash_nid must be SM3_256.
|
||||
*
|
||||
* The id_a_size must be smaller than 2^16-1.
|
||||
* The sig_size is 64. first 32-byte is R, second 32-byte is S.
|
||||
*
|
||||
* @param[in] sm2_context Pointer to SM2 context for signature verification.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] id_a The ID-A of the signing context.
|
||||
* @param[in] id_a_size Size of ID-A signing context.
|
||||
* @param[in] message Pointer to octet message to be checked (before hash).
|
||||
* @param[in] size Size of the message in bytes.
|
||||
* @param[in] signature Pointer to SM2 signature to be verified.
|
||||
* @param[in] sig_size Size of signature in bytes.
|
||||
*
|
||||
* @retval true Valid signature encoded in SM2.
|
||||
* @retval false Invalid signature or invalid sm2 context.
|
||||
*
|
||||
**/
|
||||
extern bool libspdm_sm2_dsa_verify(const void *sm2_context, size_t hash_nid,
|
||||
const uint8_t *id_a, size_t id_a_size,
|
||||
const uint8_t *message, size_t size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
#endif /* LIBSPDM_SM2_DSA_SUPPORT */
|
||||
|
||||
#if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
|
||||
/**
|
||||
* Allocates and Initializes one Shang-Mi2 context for subsequent use.
|
||||
*
|
||||
* @param nid cipher NID
|
||||
*
|
||||
* @return Pointer to the Shang-Mi2 context that has been initialized.
|
||||
* If the allocations fails, sm2_new_by_nid() returns NULL.
|
||||
**/
|
||||
extern void *libspdm_sm2_key_exchange_new_by_nid(size_t nid);
|
||||
|
||||
/**
|
||||
* Release the specified sm2 context.
|
||||
*
|
||||
* @param[in] sm2_context Pointer to the sm2 context to be released.
|
||||
*
|
||||
**/
|
||||
extern void libspdm_sm2_key_exchange_free(void *sm2_context);
|
||||
|
||||
/**
|
||||
* Initialize the specified sm2 context.
|
||||
*
|
||||
* @param[in] sm2_context Pointer to the sm2 context to be released.
|
||||
* @param[in] hash_nid hash NID, only SM3 is valid.
|
||||
* @param[in] id_a The ID-A of the key exchange context.
|
||||
* @param[in] id_a_size Size of ID-A key exchange context.
|
||||
* @param[in] id_b The ID-B of the key exchange context.
|
||||
* @param[in] id_b_size Size of ID-B key exchange context.
|
||||
* @param[in] is_initiator If the caller is initiator.
|
||||
*
|
||||
* @retval true sm2 context is initialized.
|
||||
* @retval false sm2 context is not initialized.
|
||||
**/
|
||||
extern bool libspdm_sm2_key_exchange_init(const void *sm2_context, size_t hash_nid,
|
||||
const uint8_t *id_a, size_t id_a_size,
|
||||
const uint8_t *id_b, size_t id_b_size,
|
||||
bool is_initiator);
|
||||
|
||||
/**
|
||||
* Generates sm2 key and returns sm2 public key (X, Y), based upon GB/T 32918.3-2016: SM2 - Part3.
|
||||
*
|
||||
* This function generates random secret, and computes the public key (X, Y), which is
|
||||
* returned via parameter public, public_size.
|
||||
* X is the first half of public with size being public_size / 2,
|
||||
* Y is the second half of public with size being public_size / 2.
|
||||
* sm2 context is updated accordingly.
|
||||
* If the public buffer is too small to hold the public X, Y, false is returned and
|
||||
* public_size is set to the required buffer size to obtain the public X, Y.
|
||||
*
|
||||
* The public_size is 64. first 32-byte is X, second 32-byte is Y.
|
||||
*
|
||||
* If sm2_context is NULL, then return false.
|
||||
* If public_size is NULL, then return false.
|
||||
* If public_size is large enough but public is NULL, then return false.
|
||||
*
|
||||
* @param[in, out] sm2_context Pointer to the sm2 context.
|
||||
* @param[out] public_data Pointer to the buffer to receive generated public X,Y.
|
||||
* @param[in, out] public_size On input, the size of public buffer in bytes.
|
||||
* On output, the size of data returned in public buffer in bytes.
|
||||
*
|
||||
* @retval true sm2 public X,Y generation succeeded.
|
||||
* @retval false sm2 public X,Y generation failed.
|
||||
* @retval false public_size is not large enough.
|
||||
**/
|
||||
extern bool libspdm_sm2_key_exchange_generate_key(void *sm2_context, uint8_t *public_data,
|
||||
size_t *public_size);
|
||||
|
||||
/**
|
||||
* Computes exchanged common key, based upon GB/T 32918.3-2016: SM2 - Part3.
|
||||
*
|
||||
* Given peer's public key (X, Y), this function computes the exchanged common key,
|
||||
* based on its own context including value of curve parameter and random secret.
|
||||
* X is the first half of peer_public with size being peer_public_size / 2,
|
||||
* Y is the second half of peer_public with size being peer_public_size / 2.
|
||||
*
|
||||
* If sm2_context is NULL, then return false.
|
||||
* If peer_public is NULL, then return false.
|
||||
* If peer_public_size is 0, then return false.
|
||||
* If key is NULL, then return false.
|
||||
*
|
||||
* The id_a_size and id_b_size must be smaller than 2^16-1.
|
||||
* The peer_public_size is 64. first 32-byte is X, second 32-byte is Y.
|
||||
* The key_size must be smaller than 2^32-1, limited by KDF function.
|
||||
*
|
||||
* @param[in, out] sm2_context Pointer to the sm2 context.
|
||||
* @param[in] peer_public Pointer to the peer's public X,Y.
|
||||
* @param[in] peer_public_size Size of peer's public X,Y in bytes.
|
||||
* @param[out] key Pointer to the buffer to receive generated key.
|
||||
* @param[in] key_size On input, the size of key buffer in bytes.
|
||||
*
|
||||
* @retval true sm2 exchanged key generation succeeded.
|
||||
* @retval false sm2 exchanged key generation failed.
|
||||
**/
|
||||
extern bool libspdm_sm2_key_exchange_compute_key(void *sm2_context,
|
||||
const uint8_t *peer_public,
|
||||
size_t peer_public_size, uint8_t *key,
|
||||
size_t *key_size);
|
||||
#endif /* LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT */
|
||||
#endif /* CRYPTLIB_SM2_H */
|
||||
@@ -1,91 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2024 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef LIBSPDM_LIB_CONFIG_H
|
||||
#define LIBSPDM_LIB_CONFIG_H
|
||||
|
||||
#ifndef LIBSPDM_CONFIG
|
||||
#include "library/spdm_lib_config.h"
|
||||
#else
|
||||
#include LIBSPDM_CONFIG
|
||||
#endif
|
||||
|
||||
#if defined(LIBSPDM_DEBUG_ENABLE)
|
||||
#undef LIBSPDM_DEBUG_ASSERT_ENABLE
|
||||
#undef LIBSPDM_DEBUG_PRINT_ENABLE
|
||||
#undef LIBSPDM_DEBUG_BLOCK_ENABLE
|
||||
|
||||
#define LIBSPDM_DEBUG_ASSERT_ENABLE (LIBSPDM_DEBUG_ENABLE)
|
||||
#define LIBSPDM_DEBUG_PRINT_ENABLE (LIBSPDM_DEBUG_ENABLE)
|
||||
#define LIBSPDM_DEBUG_BLOCK_ENABLE (LIBSPDM_DEBUG_ENABLE)
|
||||
#endif /* defined(LIBSPDM_DEBUG_ENABLE) */
|
||||
|
||||
/*when in FIPS mode, only support approved algo in FIPS */
|
||||
#if LIBSPDM_FIPS_MODE
|
||||
#undef LIBSPDM_SM2_DSA_P256_SUPPORT
|
||||
#define LIBSPDM_SM2_DSA_P256_SUPPORT 0
|
||||
|
||||
#undef LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT
|
||||
#define LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT 0
|
||||
|
||||
#undef LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
|
||||
#define LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT 0
|
||||
|
||||
#undef LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
|
||||
#define LIBSPDM_AEAD_SM4_128_GCM_SUPPORT 0
|
||||
|
||||
#undef LIBSPDM_SM3_256_SUPPORT
|
||||
#define LIBSPDM_SM3_256_SUPPORT 0
|
||||
#endif /*LIBSPDM_FIPS_MODE*/
|
||||
|
||||
/* define crypto algorithm without parameter */
|
||||
#define LIBSPDM_RSA_SSA_SUPPORT ((LIBSPDM_RSA_SSA_2048_SUPPORT) || \
|
||||
(LIBSPDM_RSA_SSA_3072_SUPPORT) || \
|
||||
(LIBSPDM_RSA_SSA_4096_SUPPORT))
|
||||
|
||||
#define LIBSPDM_RSA_PSS_SUPPORT ((LIBSPDM_RSA_PSS_2048_SUPPORT) || \
|
||||
(LIBSPDM_RSA_PSS_3072_SUPPORT) || \
|
||||
(LIBSPDM_RSA_PSS_4096_SUPPORT))
|
||||
|
||||
#define LIBSPDM_ECDSA_SUPPORT ((LIBSPDM_ECDSA_P256_SUPPORT) || \
|
||||
(LIBSPDM_ECDSA_P384_SUPPORT) || \
|
||||
(LIBSPDM_ECDSA_P521_SUPPORT))
|
||||
|
||||
#define LIBSPDM_SM2_DSA_SUPPORT (LIBSPDM_SM2_DSA_P256_SUPPORT)
|
||||
|
||||
#define LIBSPDM_EDDSA_SUPPORT ((LIBSPDM_EDDSA_ED25519_SUPPORT) || \
|
||||
(LIBSPDM_EDDSA_ED448_SUPPORT))
|
||||
|
||||
#define LIBSPDM_FFDHE_SUPPORT ((LIBSPDM_FFDHE_2048_SUPPORT) || \
|
||||
(LIBSPDM_FFDHE_3072_SUPPORT) || \
|
||||
(LIBSPDM_FFDHE_4096_SUPPORT))
|
||||
|
||||
#define LIBSPDM_ECDHE_SUPPORT ((LIBSPDM_ECDHE_P256_SUPPORT) || \
|
||||
(LIBSPDM_ECDHE_P384_SUPPORT) || \
|
||||
(LIBSPDM_ECDHE_P521_SUPPORT))
|
||||
|
||||
#define LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT (LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT)
|
||||
|
||||
#define LIBSPDM_AEAD_GCM_SUPPORT ((LIBSPDM_AEAD_AES_128_GCM_SUPPORT) || \
|
||||
(LIBSPDM_AEAD_AES_256_GCM_SUPPORT))
|
||||
|
||||
#define LIBSPDM_AEAD_SM4_SUPPORT (LIBSPDM_AEAD_SM4_128_GCM_SUPPORT)
|
||||
|
||||
#define LIBSPDM_SHA2_SUPPORT ((LIBSPDM_SHA256_SUPPORT) || \
|
||||
(LIBSPDM_SHA384_SUPPORT) || \
|
||||
(LIBSPDM_SHA512_SUPPORT))
|
||||
|
||||
#define LIBSPDM_SHA3_SUPPORT ((LIBSPDM_SHA3_256_SUPPORT) || \
|
||||
(LIBSPDM_SHA3_384_SUPPORT) || \
|
||||
(LIBSPDM_SHA3_512_SUPPORT))
|
||||
|
||||
#define LIBSPDM_SM3_SUPPORT (LIBSPDM_SM3_256_SUPPORT)
|
||||
|
||||
#if LIBSPDM_CHECK_MACRO
|
||||
#include "internal/libspdm_macro_check.h"
|
||||
#endif /* LIBSPDM_CHECK_MACRO */
|
||||
|
||||
#endif /* LIBSPDM_LIB_CONFIG_H */
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __INTERNAL_CRYPT_LIB_H__
|
||||
#define __INTERNAL_CRYPT_LIB_H__
|
||||
|
||||
/*
|
||||
* This code uses Linux Kernel Crypto API extensively. Web page written by
|
||||
* Stephan Mueller and Marek Vasut is a good starting reference on how linux
|
||||
* kernel provides crypto api.
|
||||
*/
|
||||
#include "conftest.h"
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/limits.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
// Check if ECDH/ECDSA are there, on some platforms they might not be...
|
||||
#ifndef AUTOCONF_INCLUDED
|
||||
#if defined(NV_GENERATED_AUTOCONF_H_PRESENT)
|
||||
#include <generated/autoconf.h>
|
||||
#else
|
||||
#include <linux/autoconf.h>
|
||||
#endif
|
||||
#endif
|
||||
#if \
|
||||
(defined(CONFIG_CRYPTO_AEAD) || defined(CONFIG_CRYPTO_AEAD_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_AKCIPHER) || defined(CONFIG_CRYPTO_AKCIPHER_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_SKCIPHER) || defined(CONFIG_CRYPTO_SKCIPHER_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_HASH) || defined(CONFIG_CRYPTO_HASH_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_HMAC) || defined(CONFIG_CRYPTO_HMAC_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_ECDH) || defined(CONFIG_CRYPTO_ECDH_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_ECDSA) || defined(CONFIG_CRYPTO_ECDSA_MODULE)) && \
|
||||
(defined(CONFIG_CRYPTO_RSA) || defined(CONFIG_CRYPTO_RSA_MODULE)) && \
|
||||
(defined(CONFIG_X509_CERTIFICATE_PARSER) || defined(CONFIG_X509_CERTIFICATE_PARSER_MODULE))
|
||||
#define NV_CONFIG_CRYPTO_PRESENT 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* It is possible that we don't have access to all the functions we have. This
|
||||
* could be either because we are running non-gpl kernel, because kernel is too
|
||||
* old or even just user disabled. If we should use LKCA, include headers, else
|
||||
* define stubs to return errors.
|
||||
*/
|
||||
#if defined(NV_CRYPTO_PRESENT) && defined (NV_CONFIG_CRYPTO_PRESENT) && \
|
||||
(defined(NV_CRYPTO_AKCIPHER_VERIFY_PRESENT) || \
|
||||
(defined(NV_CRYPTO_SIG_H_PRESENT) && defined(NV_ECC_DIGITS_FROM_BYTES_PRESENT)))
|
||||
#define USE_LKCA 1
|
||||
#endif
|
||||
|
||||
#ifdef USE_LKCA
|
||||
#include <linux/crypto.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <crypto/aead.h>
|
||||
#include <crypto/algapi.h>
|
||||
#include <crypto/hash.h>
|
||||
#include <crypto/sm3.h>
|
||||
|
||||
// HASH_MAX_DIGESTSIZE is available since 4.20.
|
||||
// This value is accurate as of 6.1
|
||||
#ifndef HASH_MAX_DIGESTSIZE
|
||||
#define HASH_MAX_DIGESTSIZE 64
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Just stub everything out
|
||||
struct shash_desc;
|
||||
struct crypto_shash;
|
||||
#define crypto_shash_setkey(...) -ENOMEM
|
||||
#define crypto_shash_init(...) -ENOMEM
|
||||
#define crypto_shash_update(...) -ENOMEM
|
||||
#define crypto_shash_update(...) -ENOMEM
|
||||
#define crypto_shash_final(...) -ENOMEM
|
||||
#endif
|
||||
|
||||
#define CHAR_BIT 8U
|
||||
#undef SIZE_MAX
|
||||
#define SIZE_MAX 8
|
||||
|
||||
#include "library/cryptlib.h"
|
||||
|
||||
#define LIBSPDM_ASSERT(...)
|
||||
struct lkca_aead_ctx;
|
||||
int lkca_aead_alloc(struct lkca_aead_ctx **ctx, char const *alg);
|
||||
void lkca_aead_free(struct lkca_aead_ctx *ctx);
|
||||
int lkca_aead_ex(struct lkca_aead_ctx *ctx,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size,
|
||||
bool enc);
|
||||
|
||||
int libspdm_aead(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size,
|
||||
bool enc, char const *alg);
|
||||
|
||||
void *lkca_hash_new(const char* alg_name);
|
||||
void lkca_hash_free(struct shash_desc *ctx);
|
||||
bool lkca_hash_duplicate(struct shash_desc *dst, struct shash_desc const *src);
|
||||
bool lkca_hash_all(const char* alg_name, const void *data,
|
||||
size_t data_size, uint8_t *hash_value);
|
||||
bool lkca_hmac_duplicate(struct shash_desc *dst, struct shash_desc const *src);
|
||||
bool lkca_hmac_set_key(struct shash_desc *ctx, const uint8_t *key, size_t key_size);
|
||||
bool lkca_hmac_all(const char* alg_name, const uint8_t *key, size_t key_size,
|
||||
const uint8_t *data, size_t data_size, uint8_t *hash_value);
|
||||
bool lkca_hkdf_extract_and_expand(const char *alg_name,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
bool lkca_hkdf_expand(const char *alg_name,
|
||||
const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size);
|
||||
|
||||
|
||||
bool lkca_ecdsa_set_priv_key(void *context, uint8_t *key, size_t key_size);
|
||||
bool lkca_ec_set_pub_key(void *ec_context, const uint8_t *public_key,
|
||||
size_t public_key_size);
|
||||
bool lkca_ec_get_pub_key(void *ec_context, uint8_t *public_key,
|
||||
size_t *public_key_size);
|
||||
bool lkca_ec_generate_key(void *ec_context, uint8_t *public_data,
|
||||
size_t *public_size);
|
||||
bool lkca_ec_compute_key(void *ec_context, const uint8_t *peer_public,
|
||||
size_t peer_public_size, uint8_t *key,
|
||||
size_t *key_size);
|
||||
bool lkca_ecdsa_verify(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
|
||||
bool lkca_rsa_verify(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size);
|
||||
|
||||
bool lkca_rsa_pkcs1_sign(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size);
|
||||
|
||||
bool lkca_rsa_pss_sign(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size);
|
||||
|
||||
#endif
|
||||
@@ -1,109 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
/** @file
|
||||
* Defines base cryptographic library APIs.
|
||||
* The Base Cryptographic Library provides implementations of basic cryptography
|
||||
* primitives (hash Serials, HMAC, AES, RSA, Diffie-Hellman, Elliptic Curve, etc) for security
|
||||
* functionality enabling.
|
||||
**/
|
||||
|
||||
#ifndef CRYPTLIB_H
|
||||
#define CRYPTLIB_H
|
||||
|
||||
#include "internal/libspdm_lib_config.h"
|
||||
|
||||
#define LIBSPDM_CRYPTO_NID_NULL 0x0000
|
||||
|
||||
/* Hash */
|
||||
#define LIBSPDM_CRYPTO_NID_SHA256 0x0001
|
||||
#define LIBSPDM_CRYPTO_NID_SHA384 0x0002
|
||||
#define LIBSPDM_CRYPTO_NID_SHA512 0x0003
|
||||
#define LIBSPDM_CRYPTO_NID_SHA3_256 0x0004
|
||||
#define LIBSPDM_CRYPTO_NID_SHA3_384 0x0005
|
||||
#define LIBSPDM_CRYPTO_NID_SHA3_512 0x0006
|
||||
#define LIBSPDM_CRYPTO_NID_SM3_256 0x0007
|
||||
|
||||
/* Signing */
|
||||
#define LIBSPDM_CRYPTO_NID_RSASSA2048 0x0101
|
||||
#define LIBSPDM_CRYPTO_NID_RSASSA3072 0x0102
|
||||
#define LIBSPDM_CRYPTO_NID_RSASSA4096 0x0103
|
||||
#define LIBSPDM_CRYPTO_NID_RSAPSS2048 0x0104
|
||||
#define LIBSPDM_CRYPTO_NID_RSAPSS3072 0x0105
|
||||
#define LIBSPDM_CRYPTO_NID_RSAPSS4096 0x0106
|
||||
#define LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256 0x0107
|
||||
#define LIBSPDM_CRYPTO_NID_ECDSA_NIST_P384 0x0108
|
||||
#define LIBSPDM_CRYPTO_NID_ECDSA_NIST_P521 0x0109
|
||||
#define LIBSPDM_CRYPTO_NID_SM2_DSA_P256 0x010A
|
||||
#define LIBSPDM_CRYPTO_NID_EDDSA_ED25519 0x010B
|
||||
#define LIBSPDM_CRYPTO_NID_EDDSA_ED448 0x010C
|
||||
|
||||
/* Key Exchange */
|
||||
#define LIBSPDM_CRYPTO_NID_FFDHE2048 0x0201
|
||||
#define LIBSPDM_CRYPTO_NID_FFDHE3072 0x0202
|
||||
#define LIBSPDM_CRYPTO_NID_FFDHE4096 0x0203
|
||||
#define LIBSPDM_CRYPTO_NID_SECP256R1 0x0204
|
||||
#define LIBSPDM_CRYPTO_NID_SECP384R1 0x0205
|
||||
#define LIBSPDM_CRYPTO_NID_SECP521R1 0x0206
|
||||
#define LIBSPDM_CRYPTO_NID_SM2_KEY_EXCHANGE_P256 0x0207
|
||||
#define LIBSPDM_CRYPTO_NID_CURVE_X25519 0x0208
|
||||
#define LIBSPDM_CRYPTO_NID_CURVE_X448 0x0209
|
||||
|
||||
/* AEAD */
|
||||
#define LIBSPDM_CRYPTO_NID_AES_128_GCM 0x0301
|
||||
#define LIBSPDM_CRYPTO_NID_AES_256_GCM 0x0302
|
||||
#define LIBSPDM_CRYPTO_NID_CHACHA20_POLY1305 0x0303
|
||||
#define LIBSPDM_CRYPTO_NID_SM4_128_GCM 0x0304
|
||||
|
||||
/* X.509 v3 key usage extension flags. */
|
||||
#define LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE 0x80
|
||||
#define LIBSPDM_CRYPTO_X509_KU_NON_REPUDIATION 0x40
|
||||
#define LIBSPDM_CRYPTO_X509_KU_KEY_ENCIPHERMENT 0x20
|
||||
#define LIBSPDM_CRYPTO_X509_KU_DATA_ENCIPHERMENT 0x10
|
||||
#define LIBSPDM_CRYPTO_X509_KU_KEY_AGREEMENT 0x08
|
||||
#define LIBSPDM_CRYPTO_X509_KU_KEY_CERT_SIGN 0x04
|
||||
#define LIBSPDM_CRYPTO_X509_KU_CRL_SIGN 0x02
|
||||
#define LIBSPDM_CRYPTO_X509_KU_ENCIPHER_ONLY 0x01
|
||||
#define LIBSPDM_CRYPTO_X509_KU_DECIPHER_ONLY 0x8000
|
||||
|
||||
/* These constants comply with the DER encoded ASN.1 type tags. */
|
||||
#define LIBSPDM_CRYPTO_ASN1_BOOLEAN 0x01
|
||||
#define LIBSPDM_CRYPTO_ASN1_INTEGER 0x02
|
||||
#define LIBSPDM_CRYPTO_ASN1_BIT_STRING 0x03
|
||||
#define LIBSPDM_CRYPTO_ASN1_OCTET_STRING 0x04
|
||||
#define LIBSPDM_CRYPTO_ASN1_NULL 0x05
|
||||
#define LIBSPDM_CRYPTO_ASN1_OID 0x06
|
||||
#define LIBSPDM_CRYPTO_ASN1_UTF8_STRING 0x0C
|
||||
#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
|
||||
#define LIBSPDM_CRYPTO_ASN1_SET 0x11
|
||||
#define LIBSPDM_CRYPTO_ASN1_PRINTABLE_STRING 0x13
|
||||
#define LIBSPDM_CRYPTO_ASN1_T61_STRING 0x14
|
||||
#define LIBSPDM_CRYPTO_ASN1_IA5_STRING 0x16
|
||||
#define LIBSPDM_CRYPTO_ASN1_UTC_TIME 0x17
|
||||
#define LIBSPDM_CRYPTO_ASN1_GENERALIZED_TIME 0x18
|
||||
#define LIBSPDM_CRYPTO_ASN1_UNIVERSAL_STRING 0x1C
|
||||
#define LIBSPDM_CRYPTO_ASN1_BMP_STRING 0x1E
|
||||
#define LIBSPDM_CRYPTO_ASN1_PRIMITIVE 0x00
|
||||
#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
|
||||
#define LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC 0x80
|
||||
|
||||
#define LIBSPDM_CRYPTO_ASN1_TAG_CLASS_MASK 0xC0
|
||||
#define LIBSPDM_CRYPTO_ASN1_TAG_PC_MASK 0x20
|
||||
#define LIBSPDM_CRYPTO_ASN1_TAG_VALUE_MASK 0x1F
|
||||
|
||||
#include "hal/library/cryptlib/cryptlib_hash.h"
|
||||
#include "hal/library/cryptlib/cryptlib_mac.h"
|
||||
#include "hal/library/cryptlib/cryptlib_aead.h"
|
||||
#include "hal/library/cryptlib/cryptlib_cert.h"
|
||||
#include "hal/library/cryptlib/cryptlib_hkdf.h"
|
||||
#include "hal/library/cryptlib/cryptlib_rsa.h"
|
||||
#include "hal/library/cryptlib/cryptlib_ec.h"
|
||||
#include "hal/library/cryptlib/cryptlib_dh.h"
|
||||
#include "hal/library/cryptlib/cryptlib_ecd.h"
|
||||
#include "hal/library/cryptlib/cryptlib_sm2.h"
|
||||
#include "hal/library/cryptlib/cryptlib_rng.h"
|
||||
|
||||
#endif /* CRYPTLIB_H */
|
||||
@@ -1,445 +0,0 @@
|
||||
/**
|
||||
* Copyright Notice:
|
||||
* Copyright 2021-2024 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
**/
|
||||
|
||||
#ifndef SPDM_LIB_CONFIG_H
|
||||
#define SPDM_LIB_CONFIG_H
|
||||
|
||||
/* Code space optimization for optional messages.
|
||||
*
|
||||
* An Integrator of libspdm may not need all of the optional SPDM messages. The
|
||||
* LIBSPDM_ENABLE_CAPABILITY_***_CAP compile time switches allow the Integrator to enable or disable
|
||||
* capabilities and messages.
|
||||
*/
|
||||
|
||||
/* SPDM 1.0 capabilities and messages. */
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_CERT_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
|
||||
#define LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES 1
|
||||
#endif
|
||||
|
||||
/* SPDM 1.1 capabilities. */
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_PSK_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP 1
|
||||
#endif
|
||||
|
||||
/* SPDM 1.2 capabilities. */
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_CSR_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP 1
|
||||
#endif
|
||||
|
||||
/* SPDM 1.3 capabilities. */
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_MEL_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP 1
|
||||
#endif
|
||||
|
||||
/* Includes SPDM 1.3 features for CSR messages. If enabled then LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
|
||||
* must also be enabled.
|
||||
*/
|
||||
#ifndef LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
|
||||
#define LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX 1
|
||||
#endif
|
||||
|
||||
/* If 1 then endpoint supports sending GET_CERTIFICATE and GET_DIGESTS requests.
|
||||
* If enabled and endpoint is a Responder then LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
|
||||
* must also be enabled.
|
||||
*/
|
||||
#ifndef LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
|
||||
#define LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/* If 1 then endpoint supports sending CHALLENGE request.
|
||||
* If enabled and endpoint is a Responder then LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
|
||||
* must also be enabled.
|
||||
*/
|
||||
#ifndef LIBSPDM_SEND_CHALLENGE_SUPPORT
|
||||
#define LIBSPDM_SEND_CHALLENGE_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/* If 1 then endpoint supports sending the GET_SUPPORTED_EVENT_TYPES, SUBSCRIBE_EVENT_TYPES, and
|
||||
* encapsulated EVENT_ACK messages. In addition, LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP must also be
|
||||
* 1.
|
||||
*/
|
||||
#ifndef LIBSPDM_EVENT_RECIPIENT_SUPPORT
|
||||
#define LIBSPDM_EVENT_RECIPIENT_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/* When LIBSPDM_RESPOND_IF_READY_SUPPORT is 0 then
|
||||
* - For a Requester, if the Responder sends a ResponseNotReady ERROR response then the error
|
||||
* is immediately returned to the Integrator. The Requester cannot send a RESPOND_IF_READY
|
||||
* request.
|
||||
* - For a Responder, it cannot send a RESPOND_IF_READY ERROR response and does not support
|
||||
* RESPOND_IF_READY.
|
||||
* When LIBSPDM_RESPOND_IF_READY_SUPPORT is 1 then
|
||||
* - For a Requester, if the Responder sends a ResponseNotReady ERROR response then libspdm
|
||||
* waits an amount of time, as specified by the RDTExponent parameter, before sending
|
||||
* RESPOND_IF_READY.
|
||||
* - For a Responder, if its response state is NOT_READY then it will send a ResponseNotReady
|
||||
* ERROR response to the Requester, and will accept a subsequent RESPOND_IF_READY request.
|
||||
*/
|
||||
#ifndef LIBSPDM_RESPOND_IF_READY_SUPPORT
|
||||
#define LIBSPDM_RESPOND_IF_READY_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/* Enables FIPS 140-3 mode. */
|
||||
#ifndef LIBSPDM_FIPS_MODE
|
||||
#define LIBSPDM_FIPS_MODE 0
|
||||
#endif
|
||||
|
||||
/* Enables assertions and debug printing. When `LIBSPDM_DEBUG_ENABLE` is defined it overrides or
|
||||
* sets the values of `LIBSPDM_DEBUG_PRINT_ENABLE`, `LIBSPDM_DEBUG_ASSERT_ENABLE`, and
|
||||
* `LIBSPDM_BLOCK_ENABLE` to the value of `LIBSPDM_DEBUG_ENABLE`.
|
||||
*
|
||||
* Note that if this file is used with CMake and `DTARGET=Release` is defined, then all debugging
|
||||
* is disabled.
|
||||
*/
|
||||
#ifndef LIBSPDM_DEBUG_ENABLE
|
||||
#define LIBSPDM_DEBUG_ENABLE 1
|
||||
#endif
|
||||
|
||||
/* The SPDM specification allows a Responder to return up to 255 version entries in the `VERSION`
|
||||
* response to the Requester, including duplicate entries. For a Requester this value specifies the
|
||||
* maximum number of entries that libspdm will tolerate in a `VERSION` response before returning an
|
||||
* error. A similar macro, `SPDM_MAX_VERSION_COUNT`, exists for the Responder. However this macro
|
||||
* is not meant to be configured by the Integrator.
|
||||
*/
|
||||
#ifndef LIBSPDM_MAX_VERSION_COUNT
|
||||
#define LIBSPDM_MAX_VERSION_COUNT 5
|
||||
#endif
|
||||
|
||||
#if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
|
||||
/* This value specifies the maximum size, in bytes, of the `PSK_EXCHANGE.RequesterContext` and,
|
||||
* if supported by the Responder, `PSK_EXCHANGE_RSP.ResponderContext` fields. The fields are
|
||||
* typically random or monotonically increasing numbers.
|
||||
*/
|
||||
#ifndef LIBSPDM_PSK_CONTEXT_LENGTH
|
||||
#define LIBSPDM_PSK_CONTEXT_LENGTH LIBSPDM_MAX_HASH_SIZE
|
||||
#endif
|
||||
|
||||
/* This value specifies the maximum size, in bytes, of the `PSK_EXCHANGE.PSKHint` field. */
|
||||
#ifndef LIBSPDM_PSK_MAX_HINT_LENGTH
|
||||
#define LIBSPDM_PSK_MAX_HINT_LENGTH 16
|
||||
#endif
|
||||
#endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
|
||||
|
||||
/* libspdm allows an Integrator to specify multiple root certificates as trust anchors when
|
||||
* verifying certificate chains from an endpoint. This value specifies the maximum number of root
|
||||
* certificates that libspdm can support.
|
||||
*/
|
||||
#ifndef LIBSPDM_MAX_ROOT_CERT_SUPPORT
|
||||
#define LIBSPDM_MAX_ROOT_CERT_SUPPORT 10
|
||||
#endif
|
||||
|
||||
/* If the Responder supports it a Requester is allowed to establish multiple secure sessions with
|
||||
* the Responder. This value specifies the maximum number of sessions libspdm can support.
|
||||
*/
|
||||
#ifndef LIBSPDM_MAX_SESSION_COUNT
|
||||
#define LIBSPDM_MAX_SESSION_COUNT 4
|
||||
#endif
|
||||
|
||||
/* This value specifies the maximum size, in bytes, of a certificate chain that can be stored in a
|
||||
* libspdm context.
|
||||
*/
|
||||
#ifndef LIBSPDM_MAX_CERT_CHAIN_SIZE
|
||||
#define LIBSPDM_MAX_CERT_CHAIN_SIZE 0x1000
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE
|
||||
#define LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE 0x1000
|
||||
#endif
|
||||
|
||||
/* Partial certificates can be retrieved from a Requester or Responder and through multiple messages
|
||||
* the complete certificate chain can be constructed. This value specifies the maximum size,
|
||||
* in bytes, of a partial certificate that can be sent or received.
|
||||
*/
|
||||
#ifndef LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
|
||||
#define LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN 1024
|
||||
#endif
|
||||
|
||||
/* Partial measurement extension log (MEL) can be retrieved from a Responder and through multiple
|
||||
* messages the complete MEL can be constructed. This value specifies the maximum size, in bytes, of
|
||||
* a partial MEL that can be sent or received.
|
||||
*/
|
||||
#ifndef LIBSPDM_MAX_MEL_BLOCK_LEN
|
||||
#define LIBSPDM_MAX_MEL_BLOCK_LEN 1024
|
||||
#endif
|
||||
|
||||
/* To ensure integrity in communication between the Requester and the Responder libspdm calculates
|
||||
* cryptographic digests and signatures over multiple requests and responses. This value specifies
|
||||
* whether libspdm will use a running calculation over the transcript, where requests and responses
|
||||
* are discarded as they are cryptographically consumed, or whether libspdm will buffer the entire
|
||||
* transcript before calculating the digest or signature.
|
||||
*
|
||||
* When LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT is 0 then a running calculation is used and less
|
||||
* memory is needed.
|
||||
* When LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT is 1 then the entire transcript is buffered and more
|
||||
* memory is needed.
|
||||
*/
|
||||
#ifndef LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
|
||||
#define LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT 0
|
||||
#endif
|
||||
|
||||
/* Cryptography Configuration
|
||||
* In each category, at least one should be selected.
|
||||
* NOTE: Not all combination can be supported. E.g. Don't mix NIST algo with SMx.*/
|
||||
|
||||
#ifndef LIBSPDM_RSA_SSA_2048_SUPPORT
|
||||
#define LIBSPDM_RSA_SSA_2048_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_RSA_SSA_3072_SUPPORT
|
||||
#define LIBSPDM_RSA_SSA_3072_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_RSA_SSA_4096_SUPPORT
|
||||
#define LIBSPDM_RSA_SSA_4096_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_RSA_PSS_2048_SUPPORT
|
||||
#define LIBSPDM_RSA_PSS_2048_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_RSA_PSS_3072_SUPPORT
|
||||
#define LIBSPDM_RSA_PSS_3072_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_RSA_PSS_4096_SUPPORT
|
||||
#define LIBSPDM_RSA_PSS_4096_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ECDSA_P256_SUPPORT
|
||||
#define LIBSPDM_ECDSA_P256_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_ECDSA_P384_SUPPORT
|
||||
#define LIBSPDM_ECDSA_P384_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_ECDSA_P521_SUPPORT
|
||||
#define LIBSPDM_ECDSA_P521_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_SM2_DSA_P256_SUPPORT
|
||||
#define LIBSPDM_SM2_DSA_P256_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_EDDSA_ED25519_SUPPORT
|
||||
#define LIBSPDM_EDDSA_ED25519_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_EDDSA_ED448_SUPPORT
|
||||
#define LIBSPDM_EDDSA_ED448_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_FFDHE_2048_SUPPORT
|
||||
#define LIBSPDM_FFDHE_2048_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_FFDHE_3072_SUPPORT
|
||||
#define LIBSPDM_FFDHE_3072_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_FFDHE_4096_SUPPORT
|
||||
#define LIBSPDM_FFDHE_4096_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_ECDHE_P256_SUPPORT
|
||||
#define LIBSPDM_ECDHE_P256_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_ECDHE_P384_SUPPORT
|
||||
#define LIBSPDM_ECDHE_P384_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_ECDHE_P521_SUPPORT
|
||||
#define LIBSPDM_ECDHE_P521_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT
|
||||
#define LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_AEAD_AES_128_GCM_SUPPORT
|
||||
#define LIBSPDM_AEAD_AES_128_GCM_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_AEAD_AES_256_GCM_SUPPORT
|
||||
#define LIBSPDM_AEAD_AES_256_GCM_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
|
||||
#define LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
|
||||
#define LIBSPDM_AEAD_SM4_128_GCM_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_SHA256_SUPPORT
|
||||
#define LIBSPDM_SHA256_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_SHA384_SUPPORT
|
||||
#define LIBSPDM_SHA384_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_SHA512_SUPPORT
|
||||
#define LIBSPDM_SHA512_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_SHA3_256_SUPPORT
|
||||
#define LIBSPDM_SHA3_256_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_SHA3_384_SUPPORT
|
||||
#define LIBSPDM_SHA3_384_SUPPORT 1
|
||||
#endif
|
||||
#ifndef LIBSPDM_SHA3_512_SUPPORT
|
||||
#define LIBSPDM_SHA3_512_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef LIBSPDM_SM3_256_SUPPORT
|
||||
#define LIBSPDM_SM3_256_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/* If 1 then endpoint supports parsing X.509 certificate chains. */
|
||||
#ifndef LIBSPDM_CERT_PARSE_SUPPORT
|
||||
#define LIBSPDM_CERT_PARSE_SUPPORT 1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* MinDataTransferSize = 42
|
||||
*
|
||||
* H = HashLen = HmacLen = [32, 64]
|
||||
* S = SigLen = [64, 512]
|
||||
* D = ExchangeDataLen = [64, 512]
|
||||
* R = RequesterContextLen >= 32
|
||||
* R = ResponderContextLen >= 0
|
||||
* O = OpaqueDataLen <= 1024
|
||||
*
|
||||
* Max Chunk No = 1, if (message size <= 42)
|
||||
* Max Chunk No = [(message size + 4) / 30] roundup, if (message size > 42)
|
||||
*
|
||||
* +==========================+==========================================+=========+
|
||||
* | Command | Size |MaxChunk |
|
||||
* +==========================+==========================================+=========+
|
||||
* | GET_VERSION | 4 | 1 |
|
||||
* | VERSION {1.0, 1.1, 1.2} | 6 + 2 * 3 = 12 | 1 |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | GET_CAPABILITIES 1.2 | 20 | 1 |
|
||||
* | CAPABILITIES 1.2 | 20 | 1 |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | ERROR | 4 | 1 |
|
||||
* | ERROR(ResponseTooLarge) | 4 + 4 = 8 | 1 |
|
||||
* | ERROR(LargeResponse) | 4 + 1 = 5 | 1 |
|
||||
* | ERROR(ResponseNotReady) | 4 + 4 = 8 | 1 |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | CHUNK_SEND header | 12 + L0 (0 or 4) | 1 |
|
||||
* | CHUNK_RESPONSE header | 12 + L0 (0 or 4) | 1 |
|
||||
* +==========================+==========================================+=========+
|
||||
* | NEGOTIATE_ALGORITHMS 1.2 | 32 + 4 * 4 = 48 | 2 |
|
||||
* | ALGORITHMS 1.2 | 36 + 4 * 4 = 52 | 2 |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | GET_DIGESTS 1.2 | 4 | 1 |
|
||||
* | DIGESTS 1.2 | 4 + H * SlotNum = [36, 516] | [1, 18] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | GET_CERTIFICATE 1.2 | 8 | 1 |
|
||||
* | CERTIFICATE 1.2 | 8 + PortionLen | [1, ] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | CHALLENGE 1.2 | 40 | 1 |
|
||||
* | CHALLENGE_AUTH 1.2 | 38 + H * 2 + S [+ O] = [166, 678] | [6, 23] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | GET_MEASUREMENTS 1.2 | 5 + Nonce (0 or 32) | 1 |
|
||||
* | MEASUREMENTS 1.2 | 42 + MeasRecLen (+ S) [+ O] = [106, 554] | [4, 19] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | KEY_EXCHANGE 1.2 | 42 + D [+ O] = [106, 554] | [4, 19] |
|
||||
* | KEY_EXCHANGE_RSP 1.2 | 42 + D + H + S (+ H) [+ O] = [234, 1194] | [8, 40] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | FINISH 1.2 | 4 (+ S) + H = [100, 580] | [4, 20] |
|
||||
* | FINISH_RSP 1.2 | 4 (+ H) = [36, 69] | [1, 3] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | PSK_EXCHANGE 1.2 | 12 [+ PSKHint] + R [+ O] = 44 | 2 |
|
||||
* | PSK_EXCHANGE_RSP 1.2 | 12 + R + H (+ H) [+ O] = [108, 172] | [4, 6] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | PSK_FINISH 1.2 | 4 + H = [36, 68] | [1, 3] |
|
||||
* | PSK_FINISH_RSP 1.2 | 4 | 1 |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | GET_CSR 1.2 | 8 + RequesterInfoLen [+ O] | [1, ] |
|
||||
* | CSR 1.2 | 8 + CSRLength | [1, ] |
|
||||
* +--------------------------+------------------------------------------+---------+
|
||||
* | SET_CERTIFICATE 1.2 | 4 + CertChainLen | [1, ] |
|
||||
* | SET_CERTIFICATE_RSP 1.2 | 4 | 1 |
|
||||
* +==========================+==========================================+=========+
|
||||
*/
|
||||
|
||||
/* Enable message logging.
|
||||
* See https://github.com/DMTF/libspdm/blob/main/doc/user_guide.md#message-logging
|
||||
* for more information.
|
||||
*/
|
||||
#ifndef LIBSPDM_ENABLE_MSG_LOG
|
||||
#define LIBSPDM_ENABLE_MSG_LOG 1
|
||||
#endif
|
||||
|
||||
/* Enable macro checking during compilation. */
|
||||
#ifndef LIBSPDM_CHECK_MACRO
|
||||
#define LIBSPDM_CHECK_MACRO 0
|
||||
#endif
|
||||
|
||||
/* Enable compilation of libspdm_check_context function. After a libspdm context has been
|
||||
* configured libspdm_check_context can be called to check that its configuration is correct.
|
||||
*/
|
||||
#ifndef LIBSPDM_CHECK_SPDM_CONTEXT
|
||||
#define LIBSPDM_CHECK_SPDM_CONTEXT 1
|
||||
#endif
|
||||
|
||||
/* Enable passing the SPDM context to HAL functions.
|
||||
* This macro will be removed when libspdm 4.0 is released.
|
||||
*/
|
||||
#ifndef LIBSPDM_HAL_PASS_SPDM_CONTEXT
|
||||
#define LIBSPDM_HAL_PASS_SPDM_CONTEXT 0
|
||||
#endif
|
||||
|
||||
/* Enable additional checks for certificates.
|
||||
* This macro will be removed when libspdm 4.0 is released.
|
||||
*/
|
||||
#ifndef LIBSPDM_ADDITIONAL_CHECK_CERT
|
||||
#define LIBSPDM_ADDITIONAL_CHECK_CERT 0
|
||||
#endif
|
||||
|
||||
#endif /* SPDM_LIB_CONFIG_H */
|
||||
@@ -1,477 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
#include "nvspdm_cryptlib_extensions.h"
|
||||
|
||||
#ifdef USE_LKCA
|
||||
#define BUFFER_SIZE (2 * 1024 * 1024)
|
||||
#define AUTH_TAG_SIZE 16
|
||||
struct lkca_aead_ctx
|
||||
{
|
||||
struct crypto_aead *aead;
|
||||
struct aead_request *req;
|
||||
char *a_data_buffer;
|
||||
char *in_buffer;
|
||||
char *out_buffer;
|
||||
char tag[AUTH_TAG_SIZE];
|
||||
};
|
||||
#endif
|
||||
|
||||
static int libspdm_aead_prealloc(void **context, char const *alg)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return -ENODEV;
|
||||
#else
|
||||
struct lkca_aead_ctx *ctx;
|
||||
|
||||
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
|
||||
if (ctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->aead = crypto_alloc_aead(alg, CRYPTO_ALG_TYPE_AEAD, 0);
|
||||
if (IS_ERR(ctx->aead)) {
|
||||
pr_notice("could not allocate AEAD algorithm\n");
|
||||
kfree(ctx);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ctx->req = aead_request_alloc(ctx->aead, GFP_KERNEL);
|
||||
if (ctx->req == NULL) {
|
||||
pr_info("could not allocate skcipher request\n");
|
||||
crypto_free_aead(ctx->aead);
|
||||
kfree(ctx);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ctx->a_data_buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
|
||||
if (ctx->a_data_buffer == NULL) {
|
||||
aead_request_free(ctx->req);
|
||||
crypto_free_aead(ctx->aead);
|
||||
kfree(ctx);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ctx->in_buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
|
||||
if (ctx->in_buffer == NULL) {
|
||||
kfree(ctx->a_data_buffer);
|
||||
aead_request_free(ctx->req);
|
||||
crypto_free_aead(ctx->aead);
|
||||
kfree(ctx);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ctx->out_buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
|
||||
if (ctx->out_buffer == NULL) {
|
||||
kfree(ctx->a_data_buffer);
|
||||
kfree(ctx->in_buffer);
|
||||
aead_request_free(ctx->req);
|
||||
crypto_free_aead(ctx->aead);
|
||||
kfree(ctx);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*context = ctx;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void libspdm_aead_free(void *context)
|
||||
{
|
||||
#ifdef USE_LKCA
|
||||
struct lkca_aead_ctx *ctx = context;
|
||||
crypto_free_aead(ctx->aead);
|
||||
aead_request_free(ctx->req);
|
||||
kfree(ctx->a_data_buffer);
|
||||
kfree(ctx->in_buffer);
|
||||
kfree(ctx->out_buffer);
|
||||
kfree(ctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define SG_AEAD_AAD 0
|
||||
#define SG_AEAD_TEXT 1
|
||||
#define SG_AEAD_SIG 2
|
||||
// Number of fields in AEAD scatterlist
|
||||
#define SG_AEAD_LEN 3
|
||||
|
||||
#ifdef USE_LKCA
|
||||
// This function doesn't do any allocs, it uses temp buffers instead
|
||||
static int lkca_aead_internal(struct crypto_aead *aead,
|
||||
struct aead_request *req,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
struct scatterlist sg_in[],
|
||||
struct scatterlist sg_out[],
|
||||
size_t a_data_size,
|
||||
size_t data_in_size,
|
||||
size_t *data_out_size,
|
||||
size_t tag_size,
|
||||
bool enc)
|
||||
{
|
||||
DECLARE_CRYPTO_WAIT(wait);
|
||||
int rc = 0;
|
||||
|
||||
if (crypto_aead_setkey(aead, key, key_size)) {
|
||||
pr_info("key could not be set\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (crypto_aead_ivsize(aead) != iv_size) {
|
||||
pr_info("iv could not be set\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
aead_request_set_ad(req, a_data_size);
|
||||
|
||||
aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP, crypto_req_done, &wait);
|
||||
|
||||
if (enc) {
|
||||
aead_request_set_crypt(req, sg_in, sg_out, data_in_size, (u8 *) iv);
|
||||
rc = crypto_wait_req(crypto_aead_encrypt(req), &wait);
|
||||
} else {
|
||||
aead_request_set_crypt(req, sg_in, sg_out, data_in_size + tag_size, (u8 *) iv);
|
||||
rc = crypto_wait_req(crypto_aead_decrypt(req), &wait);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
if (enc) {
|
||||
pr_info("aead.c: Encryption failed with error %i\n", rc);
|
||||
} else {
|
||||
pr_info("aead.c: Decryption failed with error %i\n", rc);
|
||||
if (rc == -EBADMSG) {
|
||||
pr_info("aead.c: Authentication tag mismatch!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*data_out_size = data_in_size;
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int libspdm_aead_prealloced(void *context,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size,
|
||||
bool enc)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return -ENODEV;
|
||||
#else
|
||||
int rc = 0;
|
||||
struct scatterlist sg_in[SG_AEAD_LEN];
|
||||
struct scatterlist sg_out[SG_AEAD_LEN];
|
||||
struct lkca_aead_ctx *ctx = context;
|
||||
|
||||
|
||||
sg_init_table(sg_in, SG_AEAD_LEN);
|
||||
sg_init_table(sg_out, SG_AEAD_LEN);
|
||||
|
||||
if (!virt_addr_valid(a_data)) {
|
||||
if (a_data_size > BUFFER_SIZE) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
sg_set_buf(&sg_in[SG_AEAD_AAD], ctx->a_data_buffer, a_data_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_AAD], ctx->a_data_buffer, a_data_size);
|
||||
|
||||
memcpy(ctx->a_data_buffer, a_data, a_data_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_in[SG_AEAD_AAD], a_data, a_data_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_AAD], a_data, a_data_size);
|
||||
}
|
||||
|
||||
if (!virt_addr_valid(data_in)) {
|
||||
if (data_in_size > BUFFER_SIZE) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
sg_set_buf(&sg_in[SG_AEAD_TEXT], ctx->in_buffer, data_in_size);
|
||||
memcpy(ctx->in_buffer, data_in, data_in_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_in[SG_AEAD_TEXT], data_in, data_in_size);
|
||||
}
|
||||
|
||||
if (!virt_addr_valid(data_out)) {
|
||||
if (data_in_size > BUFFER_SIZE) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
sg_set_buf(&sg_out[SG_AEAD_TEXT], ctx->out_buffer, data_in_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_out[SG_AEAD_TEXT], data_out, data_in_size);
|
||||
}
|
||||
|
||||
// Tag is small enough that memcpy is cheaper than checking if page is virtual
|
||||
if(tag_size > AUTH_TAG_SIZE) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
sg_set_buf(&sg_in[SG_AEAD_SIG], ctx->tag, tag_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_SIG], ctx->tag, tag_size);
|
||||
|
||||
if(!enc)
|
||||
memcpy(ctx->tag, tag, tag_size);
|
||||
|
||||
rc = lkca_aead_internal(ctx->aead, ctx->req, key, key_size, iv, iv_size,
|
||||
sg_in, sg_out, a_data_size, data_in_size,
|
||||
data_out_size, tag_size, enc);
|
||||
|
||||
if (enc) {
|
||||
memcpy(tag, ctx->tag, tag_size);
|
||||
}
|
||||
|
||||
if (!virt_addr_valid(data_out)) {
|
||||
memcpy(data_out, ctx->out_buffer, data_in_size);
|
||||
}
|
||||
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
int libspdm_aead(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size,
|
||||
bool enc, char const *alg)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return -ENODEV;
|
||||
#else
|
||||
struct crypto_aead *aead = NULL;
|
||||
struct aead_request *req = NULL;
|
||||
struct scatterlist sg_in[SG_AEAD_LEN];
|
||||
struct scatterlist sg_out[SG_AEAD_LEN];
|
||||
uint8_t *a_data_shadow = NULL;
|
||||
uint8_t *data_in_shadow = NULL;
|
||||
uint8_t *data_out_shadow = NULL;
|
||||
uint8_t *tag_shadow = NULL;
|
||||
int rc = 0;
|
||||
|
||||
aead = crypto_alloc_aead(alg, CRYPTO_ALG_TYPE_AEAD, 0);
|
||||
if (IS_ERR(aead)) {
|
||||
pr_notice("could not allocate AEAD algorithm\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
req = aead_request_alloc(aead, GFP_KERNEL);
|
||||
if (req == NULL) {
|
||||
pr_info("could not allocate skcipher request\n");
|
||||
rc = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_init_table(sg_in, SG_AEAD_LEN);
|
||||
sg_init_table(sg_out, SG_AEAD_LEN);
|
||||
|
||||
if (!virt_addr_valid(a_data)) {
|
||||
a_data_shadow = kmalloc(a_data_size, GFP_KERNEL);
|
||||
if (a_data_shadow == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_set_buf(&sg_in[SG_AEAD_AAD], a_data_shadow, a_data_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_AAD], a_data_shadow, a_data_size);
|
||||
|
||||
memcpy(a_data_shadow, a_data, a_data_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_in[SG_AEAD_AAD], a_data, a_data_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_AAD], a_data, a_data_size);
|
||||
}
|
||||
|
||||
if (!virt_addr_valid(data_in)) {
|
||||
data_in_shadow = kmalloc(data_in_size, GFP_KERNEL);
|
||||
if (data_in_shadow == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_set_buf(&sg_in[SG_AEAD_TEXT], data_in_shadow, data_in_size);
|
||||
|
||||
memcpy(data_in_shadow, data_in, data_in_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_in[SG_AEAD_TEXT], data_in, data_in_size);
|
||||
}
|
||||
|
||||
if (!virt_addr_valid(data_out)) {
|
||||
data_out_shadow = kmalloc(data_in_size, GFP_KERNEL);
|
||||
if (data_out_shadow == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_set_buf(&sg_out[SG_AEAD_TEXT], data_out_shadow, data_in_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_out[SG_AEAD_TEXT], data_out, data_in_size);
|
||||
}
|
||||
|
||||
if (!virt_addr_valid(tag)) {
|
||||
tag_shadow = kmalloc(tag_size, GFP_KERNEL);
|
||||
if (tag_shadow == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_set_buf(&sg_in[SG_AEAD_SIG], tag_shadow, tag_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_SIG], tag_shadow, tag_size);
|
||||
|
||||
if(!enc)
|
||||
memcpy(tag_shadow, tag, tag_size);
|
||||
} else {
|
||||
sg_set_buf(&sg_in[SG_AEAD_SIG], tag, tag_size);
|
||||
sg_set_buf(&sg_out[SG_AEAD_SIG], tag, tag_size);
|
||||
}
|
||||
|
||||
rc = lkca_aead_internal(aead, req, key, key_size, iv, iv_size,
|
||||
sg_in, sg_out, a_data_size, data_in_size,
|
||||
data_out_size, tag_size, enc);
|
||||
|
||||
if (enc && (tag_shadow != NULL))
|
||||
memcpy((uint8_t *) tag, tag_shadow, tag_size);
|
||||
|
||||
if (data_out_shadow != NULL)
|
||||
memcpy(data_out, data_out_shadow, data_in_size);
|
||||
|
||||
out:
|
||||
if (a_data_shadow != NULL)
|
||||
kfree(a_data_shadow);
|
||||
if (data_in_shadow != NULL)
|
||||
kfree(data_in_shadow);
|
||||
if (data_out != NULL)
|
||||
kfree(data_out_shadow);
|
||||
if (tag != NULL)
|
||||
kfree(tag_shadow);
|
||||
if (aead != NULL)
|
||||
crypto_free_aead(aead);
|
||||
if (req != NULL)
|
||||
aead_request_free(req);
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Wrapper to make look like libspdm
|
||||
bool libspdm_aead_gcm_prealloc(void **context)
|
||||
{
|
||||
return libspdm_aead_prealloc(context, "gcm(aes)") == 0;
|
||||
}
|
||||
|
||||
bool libspdm_aead_aes_gcm_encrypt_prealloc(void *context,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag_out, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (data_in_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (a_data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (iv_size != 12) {
|
||||
return false;
|
||||
}
|
||||
switch (key_size) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if ((tag_size < 12) || (tag_size > 16)) {
|
||||
return false;
|
||||
}
|
||||
if (data_out_size != NULL) {
|
||||
if ((*data_out_size > INT_MAX) ||
|
||||
(*data_out_size < data_in_size)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = libspdm_aead_prealloced(context, key, key_size, iv, iv_size,
|
||||
a_data, a_data_size, data_in, data_in_size,
|
||||
tag_out, tag_size, data_out, data_out_size, true);
|
||||
|
||||
*data_out_size = data_in_size;
|
||||
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
bool libspdm_aead_aes_gcm_decrypt_prealloc(void *context,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size)
|
||||
{
|
||||
int ret;
|
||||
if (data_in_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (a_data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (iv_size != 12) {
|
||||
return false;
|
||||
}
|
||||
switch (key_size) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if ((tag_size < 12) || (tag_size > 16)) {
|
||||
return false;
|
||||
}
|
||||
if (data_out_size != NULL) {
|
||||
if ((*data_out_size > INT_MAX) ||
|
||||
(*data_out_size < data_in_size)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = libspdm_aead_prealloced(context, key, key_size, iv, iv_size,
|
||||
a_data, a_data_size, data_in, data_in_size,
|
||||
(uint8_t *) tag, tag_size, data_out, data_out_size, false);
|
||||
|
||||
*data_out_size = data_in_size;
|
||||
|
||||
return ret == 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
bool libspdm_aead_aes_gcm_encrypt(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag_out, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (data_in_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (a_data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (iv_size != 12) {
|
||||
return false;
|
||||
}
|
||||
switch (key_size) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if ((tag_size < 12) || (tag_size > 16)) {
|
||||
return false;
|
||||
}
|
||||
if (data_out_size != NULL) {
|
||||
if ((*data_out_size > INT_MAX) ||
|
||||
(*data_out_size < data_in_size)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = libspdm_aead(key, key_size, iv, iv_size, a_data, a_data_size,
|
||||
data_in, data_in_size, tag_out, tag_size,
|
||||
data_out, data_out_size, true, "gcm(aes)");
|
||||
|
||||
*data_out_size = data_in_size;
|
||||
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
bool libspdm_aead_aes_gcm_decrypt(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size)
|
||||
{
|
||||
int ret;
|
||||
if (data_in_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (a_data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
if (iv_size != 12) {
|
||||
return false;
|
||||
}
|
||||
switch (key_size) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if ((tag_size < 12) || (tag_size > 16)) {
|
||||
return false;
|
||||
}
|
||||
if (data_out_size != NULL) {
|
||||
if ((*data_out_size > INT_MAX) ||
|
||||
(*data_out_size < data_in_size)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = libspdm_aead(key, key_size, iv, iv_size, a_data, a_data_size,
|
||||
data_in, data_in_size, tag, tag_size,
|
||||
data_out, data_out_size, false, "gcm(aes)");
|
||||
|
||||
*data_out_size = data_in_size;
|
||||
|
||||
return ret == 0;
|
||||
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Comments, prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
static bool lkca_ecdsa_sign(void *ec_context,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_ec_set_pub_key(void *ec_context, const uint8_t *public_key,
|
||||
size_t public_key_size)
|
||||
{
|
||||
if (ec_context == NULL || public_key == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_ec_set_pub_key(ec_context, public_key, public_key_size);
|
||||
}
|
||||
|
||||
bool libspdm_ec_get_pub_key(void *ec_context, uint8_t *public_key,
|
||||
size_t *public_key_size)
|
||||
{
|
||||
if (ec_context == NULL || public_key_size == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (public_key == NULL && *public_key_size != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_ec_get_pub_key(ec_context, public_key, public_key_size);
|
||||
}
|
||||
|
||||
bool libspdm_ec_check_key(const void *ec_context)
|
||||
{
|
||||
/* TBD*/
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_ec_generate_key(void *ec_context, uint8_t *public_data,
|
||||
size_t *public_size)
|
||||
{
|
||||
if (ec_context == NULL || public_size == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (public_data == NULL && *public_size != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_ec_generate_key(ec_context, public_data, public_size);
|
||||
}
|
||||
|
||||
bool libspdm_ec_compute_key(void *ec_context, const uint8_t *peer_public,
|
||||
size_t peer_public_size, uint8_t *key,
|
||||
size_t *key_size)
|
||||
{
|
||||
if (ec_context == NULL || peer_public == NULL || key_size == NULL ||
|
||||
key == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (peer_public_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_ec_compute_key(ec_context, peer_public, peer_public_size, key,
|
||||
key_size);
|
||||
}
|
||||
|
||||
bool libspdm_ecdsa_sign(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size)
|
||||
{
|
||||
if (ec_context == NULL || message_hash == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (signature == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (hash_nid) {
|
||||
case LIBSPDM_CRYPTO_NID_SHA256:
|
||||
if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case LIBSPDM_CRYPTO_NID_SHA384:
|
||||
if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case LIBSPDM_CRYPTO_NID_SHA512:
|
||||
if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_ecdsa_sign(ec_context, message_hash, hash_size, signature, sig_size);
|
||||
}
|
||||
|
||||
bool libspdm_ecdsa_verify(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size)
|
||||
{
|
||||
if (ec_context == NULL || message_hash == NULL || signature == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sig_size > INT_MAX || sig_size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (hash_nid) {
|
||||
case LIBSPDM_CRYPTO_NID_SHA256:
|
||||
if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case LIBSPDM_CRYPTO_NID_SHA384:
|
||||
if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case LIBSPDM_CRYPTO_NID_SHA512:
|
||||
if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_ecdsa_verify(ec_context, hash_nid, message_hash, hash_size,
|
||||
signature, sig_size);
|
||||
}
|
||||
@@ -1,410 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
#ifdef USE_LKCA
|
||||
#include <linux/module.h>
|
||||
MODULE_SOFTDEP("pre: ecdh_generic,ecdsa_generic");
|
||||
|
||||
#include <crypto/akcipher.h>
|
||||
#include <crypto/ecdh.h>
|
||||
#include <crypto/internal/ecc.h>
|
||||
#ifndef NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
#include <crypto/sig.h>
|
||||
|
||||
struct signature
|
||||
{
|
||||
u64 r[ECC_MAX_DIGITS];
|
||||
u64 s[ECC_MAX_DIGITS];
|
||||
};
|
||||
#endif // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
|
||||
#define ECDSA_PUBKEY_HEADER_XY_PRESENT (0x4)
|
||||
|
||||
struct ecc_ctx {
|
||||
unsigned int curve_id;
|
||||
u64 priv_key[ECC_MAX_DIGITS]; // In big endian
|
||||
|
||||
struct {
|
||||
// ecdsa pubkey has header indicating length of pubkey
|
||||
u8 padding[7];
|
||||
u8 pub_key_prefix;
|
||||
u64 pub_key[2 * ECC_MAX_DIGITS];
|
||||
};
|
||||
|
||||
bool pub_key_set;
|
||||
bool priv_key_set;
|
||||
char const *name;
|
||||
int size;
|
||||
};
|
||||
#endif // USE_LKCA
|
||||
|
||||
void *libspdm_ec_new_by_nid(size_t nid)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return NULL;
|
||||
#else
|
||||
struct ecc_ctx *ctx;
|
||||
|
||||
if ((nid != LIBSPDM_CRYPTO_NID_SECP256R1) && (nid != LIBSPDM_CRYPTO_NID_SECP384R1)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
|
||||
if (!ctx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (nid == LIBSPDM_CRYPTO_NID_SECP256R1) {
|
||||
ctx->curve_id = ECC_CURVE_NIST_P256;
|
||||
ctx->size = 64;
|
||||
ctx->name = "ecdsa-nist-p256";
|
||||
} else {
|
||||
ctx->curve_id = ECC_CURVE_NIST_P384;
|
||||
ctx->size = 96;
|
||||
ctx->name = "ecdsa-nist-p384";
|
||||
}
|
||||
ctx->pub_key_set = false;
|
||||
ctx->priv_key_set = false;
|
||||
|
||||
return ctx;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
void libspdm_ec_free(void *ec_context)
|
||||
{
|
||||
#ifdef USE_LKCA
|
||||
kfree(ec_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_ecdsa_set_priv_key(void *context, uint8_t *key, size_t key_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
struct ecc_ctx *ctx = context;
|
||||
unsigned int ndigits = ctx->size / 16;
|
||||
|
||||
if (key_size != (ctx->size / 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(ctx->priv_key, key, key_size);
|
||||
|
||||
// XXX: if this fails, do we want to retry generating new key?
|
||||
if(ecc_make_pub_key(ctx->curve_id, ndigits, ctx->priv_key, ctx->pub_key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx->pub_key_set = true;
|
||||
ctx->priv_key_set = true;
|
||||
return true;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
bool lkca_ec_set_pub_key(void *ec_context, const uint8_t *public_key,
|
||||
size_t public_key_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
struct ecc_ctx *ctx = ec_context;
|
||||
struct ecc_point pub_key;
|
||||
unsigned int ndigits;
|
||||
|
||||
if (public_key_size != ctx->size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We can reuse pub_key for now
|
||||
ndigits = ctx->size / 16;
|
||||
pub_key = ECC_POINT_INIT(ctx->pub_key, ctx->pub_key + ndigits, ndigits);
|
||||
|
||||
ecc_swap_digits(public_key, ctx->pub_key, ndigits);
|
||||
ecc_swap_digits(((u64 *)public_key) + ndigits, ctx->pub_key + ndigits, ndigits);
|
||||
if(ecc_is_pubkey_valid_full(ecc_get_curve(ctx->curve_id), &pub_key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(ctx->pub_key, public_key, public_key_size);
|
||||
ctx->pub_key_set = true;
|
||||
return true;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
bool lkca_ec_get_pub_key(void *ec_context, uint8_t *public_key,
|
||||
size_t *public_key_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
struct ecc_ctx *ctx = ec_context;
|
||||
|
||||
if (*public_key_size < ctx->size) {
|
||||
*public_key_size = ctx->size;
|
||||
return false;
|
||||
}
|
||||
*public_key_size = ctx->size;
|
||||
|
||||
memcpy(public_key, ctx->pub_key, ctx->size);
|
||||
return true;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
bool lkca_ec_generate_key(void *ec_context, uint8_t *public_data,
|
||||
size_t *public_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
struct ecc_ctx *ctx = ec_context;
|
||||
|
||||
unsigned int ndigits = ctx->size / 16;
|
||||
|
||||
if(ecc_gen_privkey(ctx->curve_id, ndigits, ctx->priv_key)) {
|
||||
return false;
|
||||
}
|
||||
// XXX: if this fails, do we want to retry generating new key?
|
||||
if(ecc_make_pub_key(ctx->curve_id, ndigits, ctx->priv_key, ctx->pub_key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(public_data, ctx->pub_key, ctx->size);
|
||||
*public_size = ctx->size;
|
||||
ctx->priv_key_set = true;
|
||||
ctx->pub_key_set = true;
|
||||
|
||||
return true;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
bool lkca_ec_compute_key(void *ec_context, const uint8_t *peer_public,
|
||||
size_t peer_public_size, uint8_t *key,
|
||||
size_t *key_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
struct ecc_ctx *ctx = ec_context;
|
||||
|
||||
if (peer_public_size != ctx->size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ctx->priv_key_set) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((ctx->size / 2) > *key_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (crypto_ecdh_shared_secret(ctx->curve_id, ctx->size / 16,
|
||||
(const u64 *) ctx->priv_key,
|
||||
(const u64 *) peer_public,
|
||||
(u64 *) key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*key_size = ctx->size / 2;
|
||||
return true;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
#ifndef NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
static bool lkca_ecdsa_verify_crypto_sig(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else // USE_LKCA
|
||||
struct ecc_ctx *ctx = ec_context;
|
||||
u8 *pub_key;
|
||||
int err;
|
||||
DECLARE_CRYPTO_WAIT(wait);
|
||||
struct crypto_sig * tfm = NULL;
|
||||
struct signature sig;
|
||||
|
||||
if (sig_size != ctx->size || !ctx->pub_key_set)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
tfm = crypto_alloc_sig(ctx->name, CRYPTO_ALG_TYPE_SIG, 0);
|
||||
if (IS_ERR(tfm)) {
|
||||
pr_info("crypto_alloc_sig failed in lkca_ecdsa_verify\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// modify header of pubkey to indicate size
|
||||
pub_key = (u8 *) &(ctx->pub_key_prefix);
|
||||
*pub_key = ECDSA_PUBKEY_HEADER_XY_PRESENT;
|
||||
err = crypto_sig_set_pubkey(tfm, pub_key, ctx->size + 1);
|
||||
if (err != 0)
|
||||
{
|
||||
pr_info("crypto_sig_set_pubkey failed in lkca_ecdsa_verify: %d", -err);
|
||||
goto failTfm;
|
||||
}
|
||||
|
||||
//
|
||||
// Compared to the way we receive the signature, we need to:
|
||||
// - swap order of all digits
|
||||
// - swap endianness for each digit
|
||||
//
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
ecc_digits_from_bytes(signature, ctx->size/2, sig.r, ECC_MAX_DIGITS);
|
||||
ecc_digits_from_bytes(signature + ctx->size/2, ctx->size/2, sig.s, ECC_MAX_DIGITS);
|
||||
|
||||
err = crypto_sig_verify(tfm, (void *)&sig, sizeof(sig), message_hash, hash_size);
|
||||
if (err != 0)
|
||||
{
|
||||
pr_info("crypto_sig_verify failed in lkca_ecdsa_verify %d\n", -err);
|
||||
}
|
||||
|
||||
failTfm:
|
||||
crypto_free_sig(tfm);
|
||||
|
||||
return err == 0;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
|
||||
#else // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
static bool lkca_ecdsa_verify_akcipher(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else // USE_LKCA
|
||||
struct ecc_ctx *ctx = ec_context;
|
||||
u8 *pub_key;
|
||||
int err;
|
||||
DECLARE_CRYPTO_WAIT(wait);
|
||||
|
||||
// Roundabout way
|
||||
u64 ber_max_len = 3 + 2 * (4 + (ECC_MAX_BYTES));
|
||||
u64 ber_len = 0;
|
||||
u8 *ber = NULL;
|
||||
struct akcipher_request *req = NULL;
|
||||
struct crypto_akcipher *tfm = NULL;
|
||||
struct scatterlist sg;
|
||||
|
||||
if (sig_size != ctx->size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ctx->pub_key_set == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
tfm = crypto_alloc_akcipher(ctx->name, CRYPTO_ALG_TYPE_AKCIPHER, 0);
|
||||
if (IS_ERR(tfm)) {
|
||||
pr_info("crypto_alloc_akcipher failed in lkca_ecdsa_verify\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// modify header of pubkey to indicate size
|
||||
pub_key = (u8 *) &(ctx->pub_key_prefix);
|
||||
*pub_key = ECDSA_PUBKEY_HEADER_XY_PRESENT;
|
||||
if ((err = crypto_akcipher_set_pub_key(tfm, pub_key, ctx->size + 1)) != 0) {
|
||||
pr_info("crypto_akcipher_set_pub_key failed in lkca_ecdsa_verify: %d\n", -err);
|
||||
goto failTfm;
|
||||
}
|
||||
|
||||
req = akcipher_request_alloc(tfm, GFP_KERNEL);
|
||||
if (IS_ERR(req)) {
|
||||
pr_info("akcipher_request_alloc failed in lkca_ecdsa_verify\n");
|
||||
goto failTfm;
|
||||
}
|
||||
|
||||
// We concatenate signature and hash and ship it to kernel
|
||||
ber = kmalloc(ber_max_len + hash_size, GFP_KERNEL);
|
||||
if (ber == NULL) {
|
||||
goto failReq;
|
||||
}
|
||||
|
||||
// XXX: NOTE THIS WILL WORK ONLY FOR 256 AND 384 bits. For larger keys
|
||||
// length field will be longer than 1 byte and I haven't taken care of that!
|
||||
|
||||
// Signature
|
||||
ber[ber_len++] = 0x30;
|
||||
ber[ber_len++] = 2 * (2 + ctx->size / 2);
|
||||
ber[ber_len++] = 0x02;
|
||||
if (signature[0] > 127) {
|
||||
ber[ber_len++] = ctx->size / 2 + 1;
|
||||
ber[1]++;
|
||||
ber[ber_len++] = 0;
|
||||
} else {
|
||||
ber[ber_len++] = ctx->size / 2;
|
||||
}
|
||||
memcpy(ber + ber_len, signature, sig_size / 2);
|
||||
ber_len += sig_size / 2;
|
||||
ber[ber_len++] = 0x02;
|
||||
if (signature[sig_size / 2] > 127) {
|
||||
ber[ber_len++] = ctx->size / 2 + 1;
|
||||
ber[1]++;
|
||||
ber[ber_len++] = 0;
|
||||
} else {
|
||||
ber[ber_len++] = ctx->size / 2;
|
||||
}
|
||||
memcpy(ber + ber_len, signature + sig_size / 2, sig_size / 2);
|
||||
ber_len += sig_size / 2;
|
||||
|
||||
// Just append hash, for scatterlists it can't be on stack anyway
|
||||
memcpy(ber + ber_len, message_hash, hash_size);
|
||||
|
||||
sg_init_one(&sg, ber, ber_len + hash_size);
|
||||
akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP, crypto_req_done, &wait);
|
||||
akcipher_request_set_crypt(req, &sg, NULL, ber_len, hash_size);
|
||||
err = crypto_wait_req(crypto_akcipher_verify(req), &wait);
|
||||
if (err != 0){
|
||||
pr_info("crypto_akcipher_verify failed in lkca_ecdsa_verify %d\n", -err);
|
||||
}
|
||||
|
||||
kfree(ber);
|
||||
failReq:
|
||||
akcipher_request_free(req);
|
||||
failTfm:
|
||||
crypto_free_akcipher(tfm);
|
||||
|
||||
return err == 0;
|
||||
#endif // USE_LKCA
|
||||
}
|
||||
#endif // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
|
||||
bool lkca_ecdsa_verify(void *ec_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size)
|
||||
{
|
||||
#ifndef NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
return lkca_ecdsa_verify_crypto_sig(ec_context, hash_nid, message_hash, hash_size,
|
||||
signature, sig_size);
|
||||
#else // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
return lkca_ecdsa_verify_akcipher(ec_context, hash_nid, message_hash, hash_size,
|
||||
signature, sig_size);
|
||||
#endif // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
// RFC 5869 has some very non-intuitive points, reading it is advised
|
||||
static bool lkca_hkdf_expand_only(struct crypto_shash *alg,
|
||||
const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
int ret;
|
||||
int i;
|
||||
uint8_t ctr = 1;
|
||||
uint8_t tmp[HASH_MAX_DIGESTSIZE];
|
||||
SHASH_DESC_ON_STACK(desc, alg);
|
||||
desc->tfm = alg;
|
||||
|
||||
ret = crypto_shash_setkey(desc->tfm, prk, prk_size);
|
||||
if (ret != 0) {
|
||||
pr_info("key size mismatch %ld\n", prk_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0, ctr = 1; i < out_size; i += prk_size, ctr++) {
|
||||
ret = crypto_shash_init(desc);
|
||||
if (ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
ret = crypto_shash_update(desc, out + i - prk_size, prk_size);
|
||||
if (ret) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (info_size > 0) {
|
||||
ret = crypto_shash_update(desc, info, info_size);
|
||||
if (ret) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(desc, &ctr, 1);
|
||||
if (ret)
|
||||
return false;
|
||||
|
||||
if ((out_size - i) < prk_size) {
|
||||
ret = crypto_shash_final(desc, tmp);
|
||||
if (ret) {
|
||||
return false;
|
||||
}
|
||||
memcpy(out + i, tmp, out_size - i);
|
||||
memzero_explicit(tmp, sizeof(tmp));
|
||||
} else {
|
||||
ret = crypto_shash_final(desc, out + i);
|
||||
if (ret) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hkdf_extract_and_expand(const char *alg_name,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
int ret = 0;
|
||||
struct crypto_shash *alg;
|
||||
uint8_t prk[HASH_MAX_DIGESTSIZE];
|
||||
|
||||
if (key == NULL || salt == NULL || info == NULL || out == NULL ||
|
||||
key_size > sizeof(prk) || salt_size > INT_MAX || info_size > INT_MAX ||
|
||||
out_size > (sizeof(prk) * 255)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
alg = crypto_alloc_shash(alg_name, 0, 0);
|
||||
if (IS_ERR(alg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_setkey(alg, salt, salt_size);
|
||||
if (ret != 0) {
|
||||
goto out;
|
||||
}
|
||||
ret = crypto_shash_tfm_digest(alg, key, key_size, prk);
|
||||
if (ret != 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = !lkca_hkdf_expand_only(alg, prk, crypto_shash_digestsize(alg), info, info_size, out, out_size);
|
||||
|
||||
out:
|
||||
crypto_free_shash(alg);
|
||||
return ret == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hkdf_expand(const char *alg_name,
|
||||
const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
bool ret = false;
|
||||
struct crypto_shash *alg;
|
||||
|
||||
if (prk == NULL || info == NULL || out == NULL || prk_size > (512 / 8) ||
|
||||
info_size > INT_MAX || (out_size > (prk_size * 255))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
alg = crypto_alloc_shash(alg_name, 0, 0);
|
||||
if (IS_ERR(alg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = lkca_hkdf_expand_only(alg, prk, prk_size, info, info_size, out, out_size);
|
||||
|
||||
crypto_free_shash(alg);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
bool libspdm_hkdf_sha256_extract_and_expand(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
return lkca_hkdf_extract_and_expand("hmac(sha256)", key, key_size,
|
||||
salt, salt_size, info, info_size,
|
||||
out, out_size);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha256_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size)
|
||||
{
|
||||
if (prk_out_size != (256 / 8))
|
||||
return false;
|
||||
|
||||
return libspdm_hmac_sha256_all(key, key_size, salt, salt_size, prk_out);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha256_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
return lkca_hkdf_expand("hmac(sha256)", prk, prk_size, info, info_size,
|
||||
out, out_size);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha384_extract_and_expand(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
return lkca_hkdf_extract_and_expand("hmac(sha384)", key, key_size,
|
||||
salt, salt_size, info, info_size,
|
||||
out, out_size);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha384_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size)
|
||||
{
|
||||
if (prk_out_size != (384 / 8))
|
||||
return false;
|
||||
|
||||
return libspdm_hmac_sha384_all(key, key_size, salt, salt_size, prk_out);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha384_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
return lkca_hkdf_expand("hmac(sha384)", prk, prk_size, info, info_size,
|
||||
out, out_size);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha512_extract_and_expand(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
return lkca_hkdf_extract_and_expand("hmac(sha512)", key, key_size,
|
||||
salt, salt_size, info, info_size, out,
|
||||
out_size);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha512_extract(const uint8_t *key, size_t key_size,
|
||||
const uint8_t *salt, size_t salt_size,
|
||||
uint8_t *prk_out, size_t prk_out_size)
|
||||
{
|
||||
if (prk_out_size != (512 / 8))
|
||||
return false;
|
||||
|
||||
return libspdm_hmac_sha512_all(key, key_size, salt, salt_size, prk_out);
|
||||
}
|
||||
|
||||
bool libspdm_hkdf_sha512_expand(const uint8_t *prk, size_t prk_size,
|
||||
const uint8_t *info, size_t info_size,
|
||||
uint8_t *out, size_t out_size)
|
||||
{
|
||||
return lkca_hkdf_expand("hmac(sha512)", prk, prk_size, info, info_size,
|
||||
out, out_size);
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
void *libspdm_hmac_sha256_new(void)
|
||||
{
|
||||
return lkca_hash_new("hmac(sha256)");
|
||||
}
|
||||
|
||||
void libspdm_hmac_sha256_free(void *hmac_sha256_ctx)
|
||||
{
|
||||
lkca_hash_free(hmac_sha256_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha256_set_key(void *hmac_sha256_ctx, const uint8_t *key,
|
||||
size_t key_size)
|
||||
{
|
||||
if (hmac_sha256_ctx == NULL)
|
||||
return false;
|
||||
|
||||
return lkca_hmac_set_key(hmac_sha256_ctx, key, key_size);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha256_duplicate(const void *hmac_sha256_ctx,
|
||||
void *new_hmac_sha256_ctx)
|
||||
{
|
||||
if (hmac_sha256_ctx == NULL || new_hmac_sha256_ctx == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hmac_duplicate(new_hmac_sha256_ctx, hmac_sha256_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha256_update(void *hmac_sha256_ctx, const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (hmac_sha256_ctx == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(hmac_sha256_ctx, data, data_size);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha256_final(void *hmac_sha256_ctx, uint8_t *hmac_value)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (hmac_sha256_ctx == NULL || hmac_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_final(hmac_sha256_ctx, hmac_value);
|
||||
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha256_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value)
|
||||
{
|
||||
if (hmac_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hmac_all("hmac(sha256)", key, key_size, data, data_size, hmac_value);
|
||||
}
|
||||
|
||||
void *libspdm_hmac_sha384_new(void)
|
||||
{
|
||||
return lkca_hash_new("hmac(sha384)");
|
||||
}
|
||||
|
||||
void libspdm_hmac_sha384_free(void *hmac_sha384_ctx)
|
||||
{
|
||||
lkca_hash_free(hmac_sha384_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha384_set_key(void *hmac_sha384_ctx, const uint8_t *key,
|
||||
size_t key_size)
|
||||
{
|
||||
if (hmac_sha384_ctx == NULL)
|
||||
return false;
|
||||
|
||||
return lkca_hmac_set_key(hmac_sha384_ctx, key, key_size);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha384_duplicate(const void *hmac_sha384_ctx,
|
||||
void *new_hmac_sha384_ctx)
|
||||
{
|
||||
if (hmac_sha384_ctx == NULL || new_hmac_sha384_ctx == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hmac_duplicate(new_hmac_sha384_ctx, hmac_sha384_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha384_update(void *hmac_sha384_ctx, const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (hmac_sha384_ctx == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(hmac_sha384_ctx, data, data_size);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha384_final(void *hmac_sha384_ctx, uint8_t *hmac_value)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (hmac_sha384_ctx == NULL || hmac_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_final(hmac_sha384_ctx, hmac_value);
|
||||
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha384_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value)
|
||||
{
|
||||
if (hmac_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hmac_all("hmac(sha384)", key, key_size, data, data_size, hmac_value);
|
||||
}
|
||||
|
||||
void *libspdm_hmac_sha512_new(void)
|
||||
{
|
||||
return lkca_hash_new("hmac(sha512)");
|
||||
}
|
||||
|
||||
void libspdm_hmac_sha512_free(void *hmac_sha512_ctx)
|
||||
{
|
||||
lkca_hash_free(hmac_sha512_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha512_set_key(void *hmac_sha512_ctx, const uint8_t *key,
|
||||
size_t key_size)
|
||||
{
|
||||
if (hmac_sha512_ctx == NULL)
|
||||
return false;
|
||||
|
||||
return lkca_hmac_set_key(hmac_sha512_ctx, key, key_size);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha512_duplicate(const void *hmac_sha512_ctx,
|
||||
void *new_hmac_sha512_ctx)
|
||||
{
|
||||
if (new_hmac_sha512_ctx == NULL || new_hmac_sha512_ctx == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hmac_duplicate(new_hmac_sha512_ctx, hmac_sha512_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha512_update(void *hmac_sha512_ctx, const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (hmac_sha512_ctx == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(hmac_sha512_ctx, data, data_size);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha512_final(void *hmac_sha512_ctx, uint8_t *hmac_value)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (hmac_sha512_ctx == NULL || hmac_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_final(hmac_sha512_ctx, hmac_value);
|
||||
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_hmac_sha512_all(const void *data, size_t data_size,
|
||||
const uint8_t *key, size_t key_size,
|
||||
uint8_t *hmac_value)
|
||||
{
|
||||
if (hmac_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hmac_all("hmac(sha512)", key, key_size, data, data_size, hmac_value);
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Comments, prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "os-interface.h"
|
||||
#include "internal_crypt_lib.h"
|
||||
#include "library/cryptlib.h"
|
||||
|
||||
bool libspdm_check_crypto_backend(void)
|
||||
{
|
||||
#ifdef USE_LKCA
|
||||
nv_printf(NV_DBG_INFO, "libspdm_check_crypto_backend: LKCA wrappers found.\n");
|
||||
nv_printf(NV_DBG_INFO, "libspdm_check_crypto_backend: LKCA calls may still fail if modules have not been loaded!\n");
|
||||
return true;
|
||||
#else
|
||||
nv_printf(NV_DBG_ERRORS, "libspdm_check_crypto_backend: Error - libspdm expects LKCA but found stubs!\n");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
// This is non-gpl symbol and not part of LKCA so no need to stub it out
|
||||
bool libspdm_random_bytes(uint8_t *output, size_t size)
|
||||
{
|
||||
get_random_bytes(output, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is specifically allowed by spdm
|
||||
bool libspdm_random_seed(const uint8_t *seed, size_t seed_size)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -1,613 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
#include "library/cryptlib.h"
|
||||
|
||||
#ifdef USE_LKCA
|
||||
#include <linux/module.h>
|
||||
#include <linux/mpi.h>
|
||||
#include <linux/random.h>
|
||||
|
||||
#include <crypto/akcipher.h>
|
||||
#include <crypto/internal/rsa.h>
|
||||
|
||||
/* ------------------------ Macros & Defines ------------------------------- */
|
||||
#define GET_MOST_SIGNIFICANT_BIT(keySize) (keySize > 0 ? ((keySize - 1) & 7) : 0)
|
||||
#define GET_ENC_MESSAGE_SIZE_BYTE(keySize) (keySize + 7) >> 3;
|
||||
#define PKCS1_MGF1_COUNTER_SIZE_BYTE (4)
|
||||
#define RSA_PSS_PADDING_ZEROS_SIZE_BYTE (8)
|
||||
#define RSA_PSS_TRAILER_FIELD (0xbc)
|
||||
#define SHIFT_RIGHT_AND_GET_BYTE(val, x) ((val >> x) & 0xFF)
|
||||
#ifndef BITS_TO_BYTES
|
||||
#define BITS_TO_BYTES(b) (b >> 3)
|
||||
#endif
|
||||
|
||||
static const unsigned char zeroes[RSA_PSS_PADDING_ZEROS_SIZE_BYTE] = { 0 };
|
||||
|
||||
struct rsa_ctx
|
||||
{
|
||||
struct rsa_key key;
|
||||
bool pub_key_set;
|
||||
bool priv_key_set;
|
||||
int size;
|
||||
};
|
||||
#endif // #ifdef USE_LKCA
|
||||
|
||||
/*!
|
||||
* Creating and initializing a RSA context.
|
||||
*
|
||||
* @return : A void pointer points to a RSA context
|
||||
*
|
||||
*/
|
||||
void *libspdm_rsa_new
|
||||
(
|
||||
void
|
||||
)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return NULL;
|
||||
#else
|
||||
struct rsa_ctx *ctx;
|
||||
|
||||
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
|
||||
|
||||
if (ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->pub_key_set = false;
|
||||
ctx->priv_key_set = false;
|
||||
|
||||
return ctx;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* To free a RSA context.
|
||||
*
|
||||
* @param rsa_context : A RSA context pointer
|
||||
*
|
||||
*/
|
||||
void libspdm_rsa_free
|
||||
(
|
||||
void *rsa_context
|
||||
)
|
||||
{
|
||||
#ifdef USE_LKCA
|
||||
struct rsa_ctx *ctx = rsa_context;
|
||||
|
||||
if (ctx != NULL)
|
||||
{
|
||||
if (ctx->key.n) kfree(ctx->key.n);
|
||||
if (ctx->key.e) kfree(ctx->key.e);
|
||||
if (ctx->key.d) kfree(ctx->key.d);
|
||||
if (ctx->key.q) kfree(ctx->key.q);
|
||||
if (ctx->key.p) kfree(ctx->key.p);
|
||||
if (ctx->key.dq) kfree(ctx->key.dq);
|
||||
if (ctx->key.dp) kfree(ctx->key.dp);
|
||||
if (ctx->key.qinv) kfree(ctx->key.qinv);
|
||||
kfree(ctx);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#define rsa_set_key_case(a, a_sz, A) \
|
||||
case A: \
|
||||
{ \
|
||||
if (ctx->key.a) { \
|
||||
kfree(ctx->key.a); \
|
||||
} \
|
||||
ctx->key.a = shadow_num; \
|
||||
ctx->key.a_sz = bn_size; \
|
||||
break; \
|
||||
}
|
||||
/*!
|
||||
* To set key into RSA context.
|
||||
*
|
||||
* @param rsa_context : A RSA context pointer
|
||||
* @param key_tag : Indicate key tag for RSA key
|
||||
* @param big_number : A big nuMber buffer to store rsa KEY
|
||||
* @param bn_size : The size of bug number
|
||||
*
|
||||
* @Return : True if OK; otherwise return False
|
||||
*/
|
||||
bool libspdm_rsa_set_key
|
||||
(
|
||||
void *rsa_context,
|
||||
const libspdm_rsa_key_tag_t key_tag,
|
||||
const uint8_t *big_number,
|
||||
size_t bn_size
|
||||
)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
struct rsa_ctx *ctx = rsa_context;
|
||||
uint8_t *shadow_num;
|
||||
|
||||
if (ctx == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Quick sanity check if tag is valid
|
||||
switch (key_tag)
|
||||
{
|
||||
case LIBSPDM_RSA_KEY_N:
|
||||
case LIBSPDM_RSA_KEY_E:
|
||||
case LIBSPDM_RSA_KEY_D:
|
||||
case LIBSPDM_RSA_KEY_Q:
|
||||
case LIBSPDM_RSA_KEY_P:
|
||||
case LIBSPDM_RSA_KEY_DP:
|
||||
case LIBSPDM_RSA_KEY_DQ:
|
||||
case LIBSPDM_RSA_KEY_Q_INV:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (big_number != NULL)
|
||||
{
|
||||
shadow_num = kmalloc(bn_size, GFP_KERNEL);
|
||||
if (shadow_num == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
memcpy(shadow_num, big_number, bn_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
shadow_num = NULL;
|
||||
bn_size = 0;
|
||||
}
|
||||
|
||||
switch (key_tag)
|
||||
{
|
||||
rsa_set_key_case(n, n_sz, LIBSPDM_RSA_KEY_N)
|
||||
rsa_set_key_case(e, e_sz, LIBSPDM_RSA_KEY_E)
|
||||
rsa_set_key_case(d, d_sz, LIBSPDM_RSA_KEY_D)
|
||||
rsa_set_key_case(q, q_sz, LIBSPDM_RSA_KEY_Q)
|
||||
rsa_set_key_case(p, p_sz, LIBSPDM_RSA_KEY_P)
|
||||
rsa_set_key_case(dq, dq_sz, LIBSPDM_RSA_KEY_DQ)
|
||||
rsa_set_key_case(dp, dp_sz, LIBSPDM_RSA_KEY_DP)
|
||||
rsa_set_key_case(qinv, qinv_sz, LIBSPDM_RSA_KEY_Q_INV)
|
||||
default:
|
||||
// We can't get here ever
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Perform PKCS1 MGF1 operation.
|
||||
*
|
||||
* @param mask : A mask pointer to store return data
|
||||
* @param maskedDB_length : Indicate mask data block length
|
||||
* @param seed : A seed pointer to store random values
|
||||
* @param seed_length : The seed length
|
||||
* @param hash_nid : The hash NID
|
||||
*
|
||||
* @Return : True if OK; otherwise return False
|
||||
*/
|
||||
static bool NV_PKCS1_MGF1
|
||||
(
|
||||
uint8_t *mask,
|
||||
size_t maskedDB_length,
|
||||
const uint8_t *seed,
|
||||
size_t seed_length,
|
||||
size_t hash_nid
|
||||
)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
size_t mdLength;
|
||||
size_t counter;
|
||||
size_t outLength;
|
||||
uint8_t counterBuf[4];
|
||||
void *sha384_ctx = NULL;
|
||||
uint8_t hash_value[LIBSPDM_SHA384_DIGEST_SIZE];
|
||||
bool status = false;
|
||||
|
||||
if (mask == NULL || seed == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only support SHA384 for MGF1 now.
|
||||
if (hash_nid == LIBSPDM_CRYPTO_NID_SHA384)
|
||||
{
|
||||
mdLength = LIBSPDM_SHA384_DIGEST_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sha384_ctx = libspdm_sha384_new();
|
||||
|
||||
if (sha384_ctx == NULL)
|
||||
{
|
||||
pr_err("%s : libspdm_sha384_new() failed \n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (counter = 0, outLength = 0; outLength < maskedDB_length; counter++)
|
||||
{
|
||||
counterBuf[0] = (uint8_t)SHIFT_RIGHT_AND_GET_BYTE(counter, 24);
|
||||
counterBuf[1] = (uint8_t)SHIFT_RIGHT_AND_GET_BYTE(counter, 16);
|
||||
counterBuf[2] = (uint8_t)SHIFT_RIGHT_AND_GET_BYTE(counter, 8);
|
||||
counterBuf[3] = (uint8_t)SHIFT_RIGHT_AND_GET_BYTE(counter, 0);
|
||||
|
||||
status = libspdm_sha384_init(sha384_ctx);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s: libspdm_sha384_init() failed !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
status = libspdm_sha384_update(sha384_ctx, seed, seed_length);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s: libspdm_sha384_update() failed(seed) !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
status = libspdm_sha384_update(sha384_ctx, counterBuf, 4);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s: libspdm_sha384_update() failed(counterBuf) !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
if (outLength + mdLength <= maskedDB_length)
|
||||
{
|
||||
status = libspdm_sha384_final(sha384_ctx, mask + outLength);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s: libspdm_sha384_final() failed (<= maskedDB_length) !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
outLength += mdLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = libspdm_sha384_final(sha384_ctx, hash_value);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s: libspdm_sha384_final() failed(> maskedDB_length) !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
memcpy(mask + outLength, hash_value, maskedDB_length - outLength);
|
||||
outLength = maskedDB_length;
|
||||
}
|
||||
}
|
||||
status = true;
|
||||
|
||||
_error_exit:
|
||||
libspdm_sha384_free(sha384_ctx);
|
||||
return status;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
0xbc : Trailer Field
|
||||
+-----------+
|
||||
| M |
|
||||
+-----------+
|
||||
|
|
||||
V
|
||||
Hash
|
||||
|
|
||||
V
|
||||
+--------+----------+----------+
|
||||
M' = |Padding1| mHash | salt |
|
||||
+--------+----------+----------+
|
||||
|--------------|---------------|
|
||||
|
|
||||
+--------+----------+ V
|
||||
DB = |Padding2| salt | Hash
|
||||
+--------+----------+ |
|
||||
| |
|
||||
V |
|
||||
xor <--- MGF <---|
|
||||
| |
|
||||
| |
|
||||
V V
|
||||
+-------------------+----------+----+
|
||||
EM = | maskedDB | H |0xbc|
|
||||
+-------------------+----------+----+
|
||||
|
||||
salt : The random number, we hardcode its size as hash size here.
|
||||
M' : The concatenation of padding1 + message hash + salt
|
||||
MGF : Mask generation function.
|
||||
A mask generation function takes an octet string of variable length
|
||||
and a desired output length as input, and outputs an octet string of
|
||||
the desired length
|
||||
MGF1 is a Mask Generation Function based on a hash function.
|
||||
|
||||
Padding1 : 8 zeros
|
||||
Padding2 : 0x01
|
||||
|
||||
The detail spec is at https://datatracker.ietf.org/doc/html/rfc2437
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Set keys and call PKCS1_MGF1 to generate signature.
|
||||
*
|
||||
* @param rsa_context : A RSA context pointer
|
||||
* @param hash_nid : The hash NID
|
||||
* @param message_hash : The pointer to message hash
|
||||
* @param signature : The pointer is used to store generated signature
|
||||
* @param sig_size : For input, a pointer store signature buffer size.
|
||||
* For output, a pointer store generate signature size.
|
||||
* @param salt_Length : The salt length for RSA-PSS algorithm
|
||||
*
|
||||
* @Return : True if OK; otherwise return False
|
||||
*/
|
||||
static bool nvRsaPaddingAddPkcs1PssMgf1
|
||||
(
|
||||
void *rsa_context,
|
||||
size_t hash_nid,
|
||||
const uint8_t *message_hash,
|
||||
size_t hash_size,
|
||||
uint8_t *signature,
|
||||
size_t *sig_size,
|
||||
int salt_length
|
||||
)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
bool status = false;
|
||||
struct rsa_ctx *ctx = rsa_context;
|
||||
void *sha384_ctx = NULL;
|
||||
uint32_t keySize;
|
||||
uint32_t msBits;
|
||||
size_t emLength;
|
||||
uint8_t saltBuf[64];
|
||||
size_t maskedDB_length;
|
||||
size_t i;
|
||||
uint8_t *tmp_H;
|
||||
uint8_t *tmp_P;
|
||||
int rc;
|
||||
unsigned int ret_data_size;
|
||||
MPI mpi_n = NULL;
|
||||
MPI mpi_d = NULL;
|
||||
MPI mpi_c = mpi_alloc(0);
|
||||
MPI mpi_p = mpi_alloc(0);
|
||||
|
||||
// read modulus to BN struct
|
||||
mpi_n = mpi_read_raw_data(ctx->key.n, ctx->key.n_sz);
|
||||
if (mpi_n == NULL)
|
||||
{
|
||||
pr_err("%s : mpi_n create failed !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
// read private exponent to BN struct
|
||||
mpi_d = mpi_read_raw_data(ctx->key.d, ctx->key.d_sz);
|
||||
if (mpi_d == NULL)
|
||||
{
|
||||
pr_err("%s : mpi_d create failed !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
keySize = mpi_n->nbits;
|
||||
msBits = GET_MOST_SIGNIFICANT_BIT(keySize);
|
||||
emLength = BITS_TO_BYTES(keySize);
|
||||
|
||||
if (msBits == 0)
|
||||
{
|
||||
*signature++ = 0;
|
||||
emLength--;
|
||||
}
|
||||
|
||||
if (emLength < hash_size + 2)
|
||||
{
|
||||
pr_err("%s : emLength < hash_size + 2 !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
// Now, we only support salt_length == LIBSPDM_SHA384_DIGEST_SIZE
|
||||
if (salt_length != LIBSPDM_SHA384_DIGEST_SIZE ||
|
||||
hash_nid != LIBSPDM_CRYPTO_NID_SHA384)
|
||||
{
|
||||
pr_err("%s : Invalid salt_length (%x) \n", __FUNCTION__, salt_length);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
get_random_bytes(saltBuf, salt_length);
|
||||
|
||||
maskedDB_length = emLength - hash_size - 1;
|
||||
tmp_H = signature + maskedDB_length;
|
||||
sha384_ctx = libspdm_sha384_new();
|
||||
|
||||
if (sha384_ctx == NULL)
|
||||
{
|
||||
pr_err("%s : libspdm_sha384_new() failed !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
status = libspdm_sha384_init(sha384_ctx);
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s : libspdm_sha384_init() failed !! \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
status = libspdm_sha384_update(sha384_ctx, zeroes, sizeof(zeroes));
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s : libspdm_sha384_update() with zeros failed !!\n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
status = libspdm_sha384_update(sha384_ctx, message_hash, hash_size);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s: libspdm_sha384_update() with message_hash failed !!\n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
if (salt_length)
|
||||
{
|
||||
status = libspdm_sha384_update(sha384_ctx, saltBuf, salt_length);
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s : libspdm_sha384_update() with saltBuf failed !!\n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
}
|
||||
|
||||
status = libspdm_sha384_final(sha384_ctx, tmp_H);
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s : libspdm_sha384_final() with tmp_H failed !!\n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
/* Generate dbMask in place then perform XOR on it */
|
||||
status = NV_PKCS1_MGF1(signature, maskedDB_length, tmp_H, hash_size, hash_nid);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pr_err("%s : NV_PKCS1_MGF1() failed \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
tmp_P = signature;
|
||||
tmp_P += emLength - salt_length - hash_size - 2;
|
||||
*tmp_P++ ^= 0x1;
|
||||
|
||||
if (salt_length > 0)
|
||||
{
|
||||
for (i = 0; i < salt_length; i++)
|
||||
{
|
||||
*tmp_P++ ^= saltBuf[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (msBits)
|
||||
{
|
||||
signature[0] &= 0xFF >> (8 - msBits);
|
||||
}
|
||||
|
||||
/* H is already in place so just set final 0xbc */
|
||||
signature[emLength - 1] = RSA_PSS_TRAILER_FIELD;
|
||||
|
||||
// read signature to BN struct
|
||||
mpi_p = mpi_read_raw_data(signature, emLength);
|
||||
if (mpi_p == NULL)
|
||||
{
|
||||
pr_err("%s : mpi_p() create failed !!\n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
// Staring RSA encryption with private key over signature.
|
||||
rc = mpi_powm(mpi_c, mpi_p, mpi_d, mpi_n);
|
||||
if (rc != 0)
|
||||
{
|
||||
pr_err("%s : mpi_powm() failed \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
rc = mpi_read_buffer(mpi_c, signature, *sig_size, &ret_data_size, NULL);
|
||||
if (rc != 0)
|
||||
{
|
||||
pr_err("%s : mpi_read_buffer() failed \n", __FUNCTION__);
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
if (ret_data_size > *sig_size)
|
||||
{
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
*sig_size = ret_data_size;
|
||||
status = true;
|
||||
|
||||
_error_exit:
|
||||
|
||||
mpi_free(mpi_n);
|
||||
mpi_free(mpi_d);
|
||||
mpi_free(mpi_c);
|
||||
mpi_free(mpi_p);
|
||||
|
||||
libspdm_sha384_free(sha384_ctx);
|
||||
|
||||
return status;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Perform RSA-PSS sigaature sign process with LKCA library.
|
||||
*
|
||||
* @param rsa_context : A RSA context pointer
|
||||
* @param hash_nid : The hash NID
|
||||
* @param message_hash : The pointer to message hash
|
||||
* @param signature : The pointer is used to store generated signature
|
||||
* @param sig_size : For input, a pointer store signature buffer size.
|
||||
* For output, a pointer store generate signature size.
|
||||
*
|
||||
* @Return : True if OK; otherwise return False
|
||||
*/
|
||||
bool lkca_rsa_pss_sign
|
||||
(
|
||||
void *rsa_context,
|
||||
size_t hash_nid,
|
||||
const uint8_t *message_hash,
|
||||
size_t hash_size,
|
||||
uint8_t *signature,
|
||||
size_t *sig_size
|
||||
)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return true;
|
||||
#else
|
||||
return nvRsaPaddingAddPkcs1PssMgf1(rsa_context,
|
||||
hash_nid,
|
||||
message_hash,
|
||||
hash_size,
|
||||
signature,
|
||||
sig_size,
|
||||
LIBSPDM_SHA384_DIGEST_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Comments, prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* RSA Asymmetric Cipher Wrapper Implementation.
|
||||
*
|
||||
* This file implements following APIs which provide more capabilities for RSA:
|
||||
* 1) rsa_pss_sign
|
||||
*
|
||||
* RFC 8017 - PKCS #1: RSA Cryptography Specifications version 2.2
|
||||
**/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
#include "library/cryptlib.h"
|
||||
|
||||
/**
|
||||
* Carries out the RSA-PSS signature generation with EMSA-PSS encoding scheme.
|
||||
*
|
||||
* This function carries out the RSA-PSS signature generation with EMSA-PSS encoding scheme defined in
|
||||
* RSA PKCS#1 v2.2.
|
||||
*
|
||||
* The salt length is same as digest length.
|
||||
*
|
||||
* If the signature buffer is too small to hold the contents of signature, false
|
||||
* is returned and sig_size is set to the required buffer size to obtain the signature.
|
||||
*
|
||||
* If rsa_context is NULL, then return false.
|
||||
* If message_hash is NULL, then return false.
|
||||
* If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
|
||||
* If sig_size is large enough but signature is NULL, then return false.
|
||||
*
|
||||
* @param[in] rsa_context Pointer to RSA context for signature generation.
|
||||
* @param[in] hash_nid hash NID
|
||||
* @param[in] message_hash Pointer to octet message hash to be signed.
|
||||
* @param[in] hash_size size of the message hash in bytes.
|
||||
* @param[out] signature Pointer to buffer to receive RSA-SSA PSS signature.
|
||||
* @param[in, out] sig_size 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 RSA-SSA PSS.
|
||||
* @retval false signature generation failed.
|
||||
* @retval false sig_size is too small.
|
||||
*
|
||||
**/
|
||||
bool libspdm_rsa_pss_sign(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
uint8_t *signature, size_t *sig_size)
|
||||
{
|
||||
return lkca_rsa_pss_sign(rsa_context, hash_nid, message_hash, hash_size,
|
||||
signature, sig_size);
|
||||
}
|
||||
//
|
||||
// In RM, we just need sign process; so we stub verification function.
|
||||
// Verification function is needed in GSP code only,
|
||||
//
|
||||
bool libspdm_rsa_pss_verify(void *rsa_context, size_t hash_nid,
|
||||
const uint8_t *message_hash, size_t hash_size,
|
||||
const uint8_t *signature, size_t sig_size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Comments, prototypes and checks taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
void *libspdm_sha256_new(void)
|
||||
{
|
||||
return lkca_hash_new("sha256");
|
||||
}
|
||||
|
||||
void libspdm_sha256_free(void *sha256_ctx)
|
||||
{
|
||||
lkca_hash_free(sha256_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_sha256_init(void *sha256_context)
|
||||
{
|
||||
return crypto_shash_init(sha256_context) == 0;
|
||||
}
|
||||
|
||||
bool libspdm_sha256_duplicate(const void *sha256_context,
|
||||
void *new_sha256_context)
|
||||
{
|
||||
if (sha256_context == NULL || new_sha256_context == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hash_duplicate(new_sha256_context, sha256_context);
|
||||
}
|
||||
|
||||
bool libspdm_sha256_update(void *sha256_context, const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (sha256_context == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(sha256_context, data, data_size);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_sha256_final(void *sha256_context, uint8_t *hash_value)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (sha256_context == NULL || hash_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_final(sha256_context, hash_value);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_sha256_hash_all(const void *data, size_t data_size,
|
||||
uint8_t *hash_value)
|
||||
{
|
||||
if (hash_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hash_all("sha256", data, data_size, hash_value);
|
||||
}
|
||||
|
||||
void *libspdm_sha384_new(void)
|
||||
{
|
||||
return lkca_hash_new("sha384");
|
||||
}
|
||||
|
||||
void libspdm_sha384_free(void *sha384_ctx)
|
||||
{
|
||||
lkca_hash_free(sha384_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_sha384_init(void *sha384_context)
|
||||
{
|
||||
return crypto_shash_init(sha384_context) == 0;
|
||||
}
|
||||
|
||||
bool libspdm_sha384_duplicate(const void *sha384_context,
|
||||
void *new_sha384_context)
|
||||
{
|
||||
if (sha384_context == NULL || new_sha384_context == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hash_duplicate(new_sha384_context, sha384_context);
|
||||
}
|
||||
|
||||
bool libspdm_sha384_update(void *sha384_context, const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (sha384_context == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(sha384_context, data, data_size);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_sha384_final(void *sha384_context, uint8_t *hash_value)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (sha384_context == NULL || hash_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_final(sha384_context, hash_value);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_sha384_hash_all(const void *data, size_t data_size,
|
||||
uint8_t *hash_value)
|
||||
{
|
||||
if (hash_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hash_all("sha384", data, data_size, hash_value);
|
||||
}
|
||||
|
||||
void *libspdm_sha512_new(void)
|
||||
{
|
||||
return lkca_hash_new("sha512");
|
||||
}
|
||||
|
||||
void libspdm_sha512_free(void *sha512_ctx)
|
||||
{
|
||||
lkca_hash_free(sha512_ctx);
|
||||
}
|
||||
|
||||
bool libspdm_sha512_init(void *sha512_context)
|
||||
{
|
||||
return crypto_shash_init(sha512_context) == 0;
|
||||
}
|
||||
|
||||
bool libspdm_sha512_duplicate(const void *sha512_context,
|
||||
void *new_sha512_context)
|
||||
{
|
||||
if (sha512_context == NULL || new_sha512_context == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hash_duplicate(new_sha512_context, sha512_context);
|
||||
}
|
||||
|
||||
bool libspdm_sha512_update(void *sha512_context, const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (sha512_context == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_update(sha512_context, data, data_size);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_sha512_final(void *sha512_context, uint8_t *hash_value)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (sha512_context == NULL || hash_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_final(sha512_context, hash_value);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_sha512_hash_all(const void *data, size_t data_size,
|
||||
uint8_t *hash_value)
|
||||
{
|
||||
if (hash_value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL && data_size != 0) {
|
||||
return false;
|
||||
}
|
||||
if (data_size > INT_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lkca_hash_all("sha512", data, data_size, hash_value);
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
#ifdef USE_LKCA
|
||||
#ifndef NV_CRYPTO_TFM_CTX_ALIGNED_PRESENT
|
||||
#include <crypto/internal/hash.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void *lkca_hash_new(const char* alg_name)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return NULL;
|
||||
#else
|
||||
//XXX: can we reuse crypto_shash part and just allocate desc
|
||||
struct crypto_shash *alg;
|
||||
struct shash_desc *desc;
|
||||
|
||||
alg = crypto_alloc_shash(alg_name, 0, 0);
|
||||
if (IS_ERR(alg)) {
|
||||
printk (KERN_INFO "Failed to alloc %s\n", alg_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(alg), GFP_KERNEL);
|
||||
if (desc == NULL){
|
||||
printk (KERN_INFO "Kernel out of mem\n");
|
||||
crypto_free_shash(alg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
desc->tfm = alg;
|
||||
|
||||
return desc;
|
||||
#endif
|
||||
}
|
||||
|
||||
void lkca_hash_free(struct shash_desc *ctx)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
#else
|
||||
crypto_free_shash(ctx->tfm);
|
||||
kfree(ctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hash_duplicate(struct shash_desc *dst, struct shash_desc const *src)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
SHASH_DESC_ON_STACK(tmp, src);
|
||||
|
||||
if (crypto_shash_export((struct shash_desc *) src, tmp)) {
|
||||
return false;
|
||||
}
|
||||
if (crypto_shash_import(dst, tmp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hmac_duplicate(struct shash_desc *dst, struct shash_desc const *src)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
// in LKCA hmac export doesn't export ipad/opad, so we need to WAR it
|
||||
|
||||
struct crypto_shash *src_tfm = src->tfm;
|
||||
struct crypto_shash *dst_tfm = dst->tfm;
|
||||
int ss = crypto_shash_statesize(dst_tfm);
|
||||
|
||||
#ifdef NV_CRYPTO_TFM_CTX_ALIGNED_PRESENT
|
||||
char *src_ipad = crypto_tfm_ctx_aligned(&src_tfm->base);
|
||||
char *dst_ipad = crypto_tfm_ctx_aligned(&dst_tfm->base);
|
||||
#else
|
||||
int ctx_size = crypto_shash_alg(dst_tfm)->base.cra_ctxsize;
|
||||
char *src_ipad = crypto_shash_ctx(src_tfm);
|
||||
char *dst_ipad = crypto_shash_ctx(dst_tfm);
|
||||
/*
|
||||
* Actual struct definition is hidden, so I assume data we need is at
|
||||
* the end. In 6.0 the struct has a pointer to crpyto_shash followed by:
|
||||
* 'u8 ipad[statesize];', then 'u8 opad[statesize];'
|
||||
*/
|
||||
src_ipad += ctx_size - 2 * ss;
|
||||
dst_ipad += ctx_size - 2 * ss;
|
||||
#endif
|
||||
|
||||
memcpy(dst_ipad, src_ipad, crypto_shash_blocksize(src->tfm));
|
||||
memcpy(dst_ipad + ss, src_ipad + ss, crypto_shash_blocksize(src->tfm));
|
||||
crypto_shash_clear_flags(dst->tfm, CRYPTO_TFM_NEED_KEY);
|
||||
|
||||
return lkca_hash_duplicate(dst, src);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hash_all(const char* alg_name, const void *data,
|
||||
size_t data_size, uint8_t *hash_value)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
int ret;
|
||||
struct crypto_shash *alg;
|
||||
alg = crypto_alloc_shash(alg_name, 0, 0);
|
||||
if (IS_ERR(alg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_tfm_digest(alg, data, data_size, hash_value);
|
||||
|
||||
crypto_free_shash(alg);
|
||||
|
||||
return (ret == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hmac_set_key(struct shash_desc *desc, const uint8_t *key, size_t key_size)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
int ret;
|
||||
ret = crypto_shash_setkey(desc->tfm, key, key_size);
|
||||
if (ret == 0) {
|
||||
ret = crypto_shash_init(desc);
|
||||
}
|
||||
return ret == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool lkca_hmac_all(const char* alg_name, const uint8_t *key, size_t key_size,
|
||||
const uint8_t *data, size_t data_size, uint8_t *hash_value)
|
||||
{
|
||||
#ifndef USE_LKCA
|
||||
return false;
|
||||
#else
|
||||
int ret;
|
||||
struct crypto_shash *alg;
|
||||
alg = crypto_alloc_shash(alg_name, 0, 0);
|
||||
if (IS_ERR(alg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = crypto_shash_setkey(alg, key, key_size);
|
||||
|
||||
if (ret == 0){
|
||||
ret = crypto_shash_tfm_digest(alg, data, data_size, hash_value);
|
||||
}
|
||||
|
||||
crypto_free_shash(alg);
|
||||
|
||||
return (ret == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,682 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* libspdm_x509_verify_cert_chain, libspdm_x509_get_cert_from_cert_chain, check
|
||||
* and prototypes taken from DMTF: Copyright 2021-2022 DMTF. All rights reserved.
|
||||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
||||
*/
|
||||
|
||||
#include "internal_crypt_lib.h"
|
||||
|
||||
#ifdef USE_LKCA
|
||||
#include <crypto/public_key.h>
|
||||
#include <keys/asymmetric-type.h>
|
||||
#endif
|
||||
|
||||
bool libspdm_x509_construct_certificate(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t **single_x509_cert)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_construct_certificate_stack(uint8_t **x509_stack, ...)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void libspdm_x509_free(void *x509_cert)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
}
|
||||
|
||||
void libspdm_x509_stack_free(void *x509_stack)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
}
|
||||
|
||||
#ifdef USE_LKCA
|
||||
bool libspdm_encode_base64(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen)
|
||||
{
|
||||
static const uint8_t base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
size_t i;
|
||||
size_t tmp;
|
||||
size_t size;
|
||||
uint8_t *ptr = dst;
|
||||
|
||||
for (i = 0; (i + 2) < srclen; i += 3)
|
||||
{
|
||||
if (ptr - dst + 4 > *p_dstlen)
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
tmp = (src[i] << 16) | (src[i+1] << 8) | (src[i+2]);
|
||||
*ptr++ = base64[(tmp >> 18) & 63];
|
||||
*ptr++ = base64[(tmp >> 12) & 63];
|
||||
*ptr++ = base64[(tmp >> 6) & 63];
|
||||
*ptr++ = base64[tmp & 63];
|
||||
}
|
||||
|
||||
// 1 byte extra
|
||||
if (i == srclen - 1)
|
||||
{
|
||||
if (ptr - dst + 4 > *p_dstlen)
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
tmp = src[i] << 4;
|
||||
*ptr++ = base64[(tmp >> 6) & 63];
|
||||
*ptr++ = base64[tmp & 63];
|
||||
*ptr++ = '=';
|
||||
*ptr++ = '=';
|
||||
}
|
||||
|
||||
// 2 byte extra
|
||||
if (i == srclen - 2)
|
||||
{
|
||||
if (ptr - dst + 4 > *p_dstlen)
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
tmp = ((src[i] << 8) | (src[i+1])) << 2;
|
||||
*ptr++ = base64[(tmp >> 12) & 63];
|
||||
*ptr++ = base64[(tmp >> 6) & 63];
|
||||
*ptr++ = base64[tmp & 63];
|
||||
*ptr++ = '=';
|
||||
}
|
||||
|
||||
*p_dstlen = ptr - dst;
|
||||
return true;
|
||||
Exit:
|
||||
*p_dstlen = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
BASE64_CONV_VALID,
|
||||
BASE64_CONV_PAD,
|
||||
BASE64_CONV_INVALID
|
||||
} BASE64_CONV;
|
||||
|
||||
static BASE64_CONV libspdm_decode_base64_chr(uint8_t b64_chr, uint8_t *value)
|
||||
{
|
||||
if (b64_chr >= 'A' && b64_chr <= 'Z')
|
||||
{
|
||||
*value = b64_chr - 'A';
|
||||
}
|
||||
else if (b64_chr >= 'a' && b64_chr <= 'z')
|
||||
{
|
||||
*value = b64_chr - 'a' + 26;
|
||||
}
|
||||
else if (b64_chr >= '0' && b64_chr <= '9')
|
||||
{
|
||||
*value = b64_chr -'0' + 52;
|
||||
}
|
||||
else if (b64_chr == '+' || b64_chr == '-')
|
||||
{
|
||||
*value = 62;
|
||||
}
|
||||
else if (b64_chr == '/' || b64_chr == '_')
|
||||
{
|
||||
*value = 63;
|
||||
}
|
||||
else if (b64_chr == '=')
|
||||
{
|
||||
*value = 0;
|
||||
return BASE64_CONV_PAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
return BASE64_CONV_INVALID;
|
||||
}
|
||||
|
||||
return BASE64_CONV_VALID;
|
||||
}
|
||||
|
||||
static bool libspdm_decode_base64_stripped(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen)
|
||||
{
|
||||
const uint8_t *p_read;
|
||||
uint8_t *p_write;
|
||||
uint8_t i;
|
||||
uint8_t bytes;
|
||||
uint32_t bin_value;
|
||||
uint8_t char_value;
|
||||
|
||||
if (src == NULL || dst == NULL || srclen % 4 != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (p_read = src, p_write = dst; p_read < src + srclen; p_read += 4)
|
||||
{
|
||||
for (i = 0, bytes = 3, bin_value = 0; i < 4; i++)
|
||||
{
|
||||
if (libspdm_decode_base64_chr(p_read[i], &char_value) == BASE64_CONV_PAD)
|
||||
{
|
||||
bytes--;
|
||||
// fallthrough
|
||||
bin_value <<= 6;
|
||||
bin_value |= char_value;
|
||||
}
|
||||
else if (libspdm_decode_base64_chr(p_read[i], &char_value) == BASE64_CONV_VALID)
|
||||
{
|
||||
bin_value <<= 6;
|
||||
bin_value |= char_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// attempting to decode an invalid character
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (p_write - dst + bytes > *p_dstlen)
|
||||
{
|
||||
// buffer too small
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
switch (bytes)
|
||||
{
|
||||
case 3:
|
||||
*p_write++ = (bin_value & 0x00ff0000) >> 16;
|
||||
*p_write++ = (bin_value & 0x0000ff00) >> 8;
|
||||
*p_write++ = (bin_value & 0x000000ff);
|
||||
break;
|
||||
case 2:
|
||||
*p_write++ = (bin_value & 0x00ff0000) >> 16;
|
||||
*p_write++ = (bin_value & 0x0000ff00) >> 8;
|
||||
break;
|
||||
case 1:
|
||||
*p_write++ = (bin_value & 0x00ff0000) >> 16;
|
||||
break;
|
||||
default:
|
||||
// invalid state in base64
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
*p_dstlen = p_write - dst;
|
||||
return true;
|
||||
Exit:
|
||||
*p_dstlen = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_decode_base64(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen)
|
||||
{
|
||||
size_t s_progress;
|
||||
size_t d_progress;
|
||||
size_t decode_size;
|
||||
size_t decoded_size;
|
||||
|
||||
// for each round we decode 64 bytes and skip the linebreaks
|
||||
for (s_progress = d_progress = 0; s_progress < srclen; s_progress += 65)
|
||||
{
|
||||
if (s_progress + 65 < srclen)
|
||||
{
|
||||
decode_size = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
// -1 to avoid decoding the '\n' byte in the end
|
||||
decode_size = srclen - s_progress - 1;
|
||||
}
|
||||
// calculate the size after decoding
|
||||
decoded_size = (decode_size / 4) * 3;
|
||||
if (src[decode_size - 1] == '=')
|
||||
{
|
||||
decoded_size--;
|
||||
}
|
||||
if (src[decoded_size - 2] == '=')
|
||||
{
|
||||
decoded_size--;
|
||||
}
|
||||
// break early if the buffer is too small
|
||||
if (*p_dstlen - d_progress < decoded_size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (!libspdm_decode_base64_stripped(src + s_progress, dst + d_progress, decode_size, &decoded_size))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
d_progress += decoded_size;
|
||||
}
|
||||
if (s_progress < srclen)
|
||||
{
|
||||
*p_dstlen = 0;
|
||||
return false;
|
||||
}
|
||||
*p_dstlen = d_progress;
|
||||
return true;
|
||||
}
|
||||
#else // USE_LKCA
|
||||
bool libspdm_encode_base64(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_decode_base64(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // USE_LKCA
|
||||
|
||||
static bool lkca_asn1_get_tag(uint8_t const *ptr, uint8_t const *end,
|
||||
size_t *length, uint32_t tag)
|
||||
{
|
||||
uint64_t max_len = end - ptr;
|
||||
|
||||
// Chain must be less than 1 GB
|
||||
if ((max_len < 2) || (max_len > (1024 * 1024 * 1024))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We only deal with universal and application tags
|
||||
if (ptr[0] != tag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ptr[1] < 0x80) {
|
||||
*length = ptr[1] + 2;
|
||||
} else if (ptr[1] == 0x81) {
|
||||
if (max_len < 3) {
|
||||
return false;
|
||||
}
|
||||
*length = ptr[2] + 3;
|
||||
} else if (ptr[1] == 0x82) {
|
||||
if (max_len < 4) {
|
||||
return false;
|
||||
}
|
||||
*length = (ptr[2] << 8) + ptr[3] + 4;
|
||||
} else {
|
||||
// In theory it could be bigger than 64KB
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*length > max_len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool libspdm_asn1_get_tag(uint8_t **ptr, const uint8_t *end, size_t *length,
|
||||
uint32_t tag)
|
||||
{
|
||||
return lkca_asn1_get_tag(*ptr, end, length, tag);
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_subject_name(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *cert_subject,
|
||||
size_t *subject_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_common_name(const uint8_t *cert, size_t cert_size,
|
||||
char *common_name,
|
||||
size_t *common_name_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
libspdm_x509_get_organization_name(const uint8_t *cert, size_t cert_size,
|
||||
char *name_buffer,
|
||||
size_t *name_buffer_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
|
||||
bool libspdm_rsa_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **rsa_context)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
#endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
|
||||
|
||||
bool libspdm_ec_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **ec_context)
|
||||
{
|
||||
#ifdef USE_LKCA
|
||||
bool ret = false;
|
||||
uint32_t key_size = 0;
|
||||
struct key_preparsed_payload lkca_cert;
|
||||
struct public_key *pub;
|
||||
|
||||
lkca_cert.data = cert;
|
||||
lkca_cert.datalen = cert_size;
|
||||
|
||||
if (cert == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(key_type_asymmetric.preparse(&lkca_cert)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub = lkca_cert.payload.data[asym_crypto];
|
||||
// -1 is since lkca prepends '4' to public keys...
|
||||
key_size = pub->keylen - 1;
|
||||
|
||||
if (key_size == (2 * 256 / 8)) {
|
||||
*ec_context = libspdm_ec_new_by_nid(LIBSPDM_CRYPTO_NID_SECP256R1);
|
||||
} else if (key_size == (2 * 384 / 8)) {
|
||||
*ec_context = libspdm_ec_new_by_nid(LIBSPDM_CRYPTO_NID_SECP384R1);
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (*ec_context == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Again skip '4' in key to be in line with spdm protocol. We will add it
|
||||
// back in ecda_verify
|
||||
if (!lkca_ec_set_pub_key(*ec_context, (char *) pub->key + 1, key_size)) {
|
||||
libspdm_ec_free(*ec_context);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = true;
|
||||
err:
|
||||
key_type_asymmetric.free_preparse(&lkca_cert);
|
||||
return ret;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool libspdm_ecd_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **ecd_context)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_sm2_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
|
||||
void **sm2_context)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
static int lkca_x509_verify_cert(const uint8_t *cert, size_t cert_size,
|
||||
const uint8_t *ca_cert, size_t ca_cert_size)
|
||||
{
|
||||
#ifdef USE_LKCA
|
||||
int ret;
|
||||
struct key_preparsed_payload lkca_cert;
|
||||
struct key_preparsed_payload lkca_ca_cert;
|
||||
|
||||
lkca_cert.data = cert;
|
||||
lkca_cert.datalen = cert_size;
|
||||
lkca_ca_cert.data = ca_cert;
|
||||
lkca_ca_cert.datalen = ca_cert_size;
|
||||
|
||||
ret = key_type_asymmetric.preparse(&lkca_cert);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = key_type_asymmetric.preparse(&lkca_ca_cert);
|
||||
if (ret) {
|
||||
key_type_asymmetric.free_preparse(&lkca_cert);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = public_key_verify_signature(lkca_ca_cert.payload.data[asym_crypto],
|
||||
lkca_cert.payload.data[asym_auth]);
|
||||
|
||||
key_type_asymmetric.free_preparse(&lkca_cert);
|
||||
key_type_asymmetric.free_preparse(&lkca_ca_cert);
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool libspdm_x509_verify_cert(const uint8_t *cert, size_t cert_size,
|
||||
const uint8_t *ca_cert, size_t ca_cert_size)
|
||||
{
|
||||
return lkca_x509_verify_cert(cert, cert_size, ca_cert, ca_cert_size) == 0;
|
||||
}
|
||||
|
||||
bool libspdm_x509_verify_cert_chain(const uint8_t *root_cert, size_t root_cert_length,
|
||||
const uint8_t *cert_chain, size_t cert_chain_length)
|
||||
{
|
||||
size_t preceding_cert_len;
|
||||
const uint8_t *preceding_cert;
|
||||
size_t current_cert_len;
|
||||
const uint8_t *current_cert;
|
||||
bool verify_flag;
|
||||
int ret;
|
||||
|
||||
verify_flag = false;
|
||||
preceding_cert = root_cert;
|
||||
preceding_cert_len = root_cert_length;
|
||||
|
||||
current_cert = cert_chain;
|
||||
|
||||
|
||||
/* Get Current certificate from certificates buffer and Verify with preceding cert*/
|
||||
do {
|
||||
if (!lkca_asn1_get_tag(
|
||||
current_cert, cert_chain + cert_chain_length, ¤t_cert_len,
|
||||
LIBSPDM_CRYPTO_ASN1_CONSTRUCTED | LIBSPDM_CRYPTO_ASN1_SEQUENCE)) {
|
||||
break;
|
||||
}
|
||||
|
||||
ret = lkca_x509_verify_cert(current_cert, current_cert_len,
|
||||
preceding_cert, preceding_cert_len);
|
||||
if (ret != 0) {
|
||||
verify_flag = false;
|
||||
break;
|
||||
} else {
|
||||
verify_flag = true;
|
||||
}
|
||||
|
||||
preceding_cert = current_cert;
|
||||
preceding_cert_len = current_cert_len;
|
||||
|
||||
current_cert = current_cert + current_cert_len;
|
||||
} while (true);
|
||||
|
||||
return verify_flag;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_cert_from_cert_chain(const uint8_t *cert_chain,
|
||||
size_t cert_chain_length,
|
||||
const int32_t cert_index, const uint8_t **cert,
|
||||
size_t *cert_length)
|
||||
{
|
||||
size_t asn1_len;
|
||||
int32_t current_index;
|
||||
size_t current_cert_len;
|
||||
const uint8_t *current_cert;
|
||||
|
||||
current_cert_len = 0;
|
||||
|
||||
/* Check input parameters.*/
|
||||
if ((cert_chain == NULL) || (cert == NULL) || (cert_index < -1) ||
|
||||
(cert_length == NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
current_cert = cert_chain;
|
||||
current_index = -1;
|
||||
|
||||
/* Traverse the certificate chain*/
|
||||
while (true) {
|
||||
/* Get asn1 tag len*/
|
||||
if (!lkca_asn1_get_tag(
|
||||
current_cert, cert_chain + cert_chain_length, &asn1_len,
|
||||
LIBSPDM_CRYPTO_ASN1_CONSTRUCTED | LIBSPDM_CRYPTO_ASN1_SEQUENCE)) {
|
||||
break;
|
||||
}
|
||||
|
||||
current_cert_len = asn1_len;
|
||||
current_index++;
|
||||
|
||||
if (current_index == cert_index) {
|
||||
*cert = current_cert;
|
||||
*cert_length = current_cert_len;
|
||||
return true;
|
||||
}
|
||||
|
||||
current_cert = current_cert + current_cert_len;
|
||||
}
|
||||
|
||||
/* If cert_index is -1, Return the last certificate*/
|
||||
if (cert_index == -1 && current_index >= 0) {
|
||||
*cert = current_cert - current_cert_len;
|
||||
*cert_length = current_cert_len;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_tbs_cert(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t **tbs_cert, size_t *tbs_cert_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_version(const uint8_t *cert, size_t cert_size,
|
||||
size_t *version)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_serial_number(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *serial_number,
|
||||
size_t *serial_number_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_issuer_name(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *cert_issuer,
|
||||
size_t *issuer_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
libspdm_x509_get_issuer_common_name(const uint8_t *cert, size_t cert_size,
|
||||
char *common_name,
|
||||
size_t *common_name_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
libspdm_x509_get_issuer_orgnization_name(const uint8_t *cert, size_t cert_size,
|
||||
char *name_buffer,
|
||||
size_t *name_buffer_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_signature_algorithm(const uint8_t *cert,
|
||||
size_t cert_size, uint8_t *oid,
|
||||
size_t *oid_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_extension_data(const uint8_t *cert, size_t cert_size,
|
||||
const uint8_t *oid, size_t oid_size,
|
||||
uint8_t *extension_data,
|
||||
size_t *extension_data_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_validity(const uint8_t *cert, size_t cert_size,
|
||||
uint8_t *from, size_t *from_size, uint8_t *to,
|
||||
size_t *to_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_key_usage(const uint8_t *cert, size_t cert_size,
|
||||
size_t *usage)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_extended_key_usage(const uint8_t *cert,
|
||||
size_t cert_size, uint8_t *usage,
|
||||
size_t *usage_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_get_extended_basic_constraints(const uint8_t *cert,
|
||||
size_t cert_size,
|
||||
uint8_t *basic_constraints,
|
||||
size_t *basic_constraints_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool libspdm_x509_set_date_time(char const *date_time_str, void *date_time, size_t *date_time_size)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t libspdm_x509_compare_date_time(const void *date_time1, const void *date_time2)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return -3;
|
||||
}
|
||||
|
||||
bool libspdm_gen_x509_csr(size_t hash_nid, size_t asym_nid,
|
||||
uint8_t *requester_info, size_t requester_info_length,
|
||||
void *context, char *subject_name,
|
||||
size_t *csr_len, uint8_t **csr_pointer)
|
||||
{
|
||||
LIBSPDM_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
|
||||
#include "os-interface.h"
|
||||
#include "nv-linux.h"
|
||||
|
||||
#if IS_ENABLED(CONFIG_TEGRA_BPMP)
|
||||
#include <soc/tegra/bpmp-abi.h>
|
||||
#include <soc/tegra/bpmp.h>
|
||||
#endif // IS_ENABLED(CONFIG_TEGRA_BPMP)
|
||||
|
||||
/*!
|
||||
* @brief Sends an MRQ (message-request) to BPMP
|
||||
*
|
||||
* The request, response, and ret parameters of this function correspond to the
|
||||
* components of the tegra_bpmp_message struct, which BPMP uses to receive
|
||||
* MRQs.
|
||||
*
|
||||
* @param[in] nv Per GPU Linux state
|
||||
* @param[in] mrq MRQ_xxx ID specifying what is requested
|
||||
* @param[in] request_data Pointer to request input data
|
||||
* @param[in] request_data_size Size of structure pointed to by pRequestData
|
||||
* @param[out] response_data Pointer to response output data
|
||||
* @param[in] response_data_size Size of structure pointed to by pResponseData
|
||||
* @param[out] ret MRQ return code (from "ret" element of
|
||||
* tegra_bpmp_message struct)
|
||||
* @param[out] api_ret Return code from tegra_bpmp_transfer call
|
||||
*
|
||||
* @returns NV_OK if successful,
|
||||
* NV_ERR_NOT_SUPPORTED if the functionality is not available,
|
||||
* NV_ERR_INVALID_POINTER if the tegra_bpmp struct pointer could not
|
||||
* be obtained from nv, or
|
||||
* NV_ERR_GENERIC if the tegra_bpmp_transfer call failed (see apiRet
|
||||
* for Linux error code).
|
||||
*/
|
||||
NV_STATUS NV_API_CALL
|
||||
nv_bpmp_send_mrq
|
||||
(
|
||||
nv_state_t *nv,
|
||||
NvU32 mrq,
|
||||
const void *request_data,
|
||||
NvU32 request_data_size,
|
||||
void *response_data,
|
||||
NvU32 response_data_size,
|
||||
NvS32 *ret,
|
||||
NvS32 *api_ret
|
||||
)
|
||||
{
|
||||
#if IS_ENABLED(CONFIG_TEGRA_BPMP) && NV_SUPPORTS_PLATFORM_DEVICE
|
||||
nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
|
||||
struct tegra_bpmp *bpmp;
|
||||
struct tegra_bpmp_message msg;
|
||||
|
||||
bpmp = tegra_bpmp_get(nvl->dev);
|
||||
if (IS_ERR(bpmp))
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS,
|
||||
"NVRM: Error getting bpmp struct: %s\n",
|
||||
PTR_ERR(bpmp));
|
||||
return NV_ERR_INVALID_POINTER;
|
||||
}
|
||||
|
||||
// Send the MRQ request to BPMP.
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.mrq = mrq;
|
||||
msg.tx.data = request_data;
|
||||
msg.tx.size = (size_t) request_data_size;
|
||||
msg.rx.data = response_data;
|
||||
msg.rx.size = (size_t) response_data_size;
|
||||
|
||||
*api_ret = (NvS32) tegra_bpmp_transfer(bpmp, &msg);
|
||||
|
||||
if (*api_ret == 0)
|
||||
{
|
||||
*ret = (NvS32) msg.rx.ret;
|
||||
return NV_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NV_ERR_GENERIC;
|
||||
}
|
||||
#else
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "nv-linux.h"
|
||||
#include "nv-caps-imex.h"
|
||||
|
||||
extern int NVreg_ImexChannelCount;
|
||||
extern int NVreg_CreateImexChannel0;
|
||||
|
||||
static int nv_caps_imex_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nv_caps_imex_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations g_nv_caps_imex_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.open = nv_caps_imex_open,
|
||||
.release = nv_caps_imex_release
|
||||
};
|
||||
|
||||
static struct class *g_nv_caps_imex_class;
|
||||
|
||||
static struct
|
||||
{
|
||||
NvBool initialized;
|
||||
struct cdev cdev;
|
||||
dev_t channel0;
|
||||
|
||||
struct device *dev_channel0;
|
||||
} g_nv_caps_imex;
|
||||
|
||||
int NV_API_CALL nv_caps_imex_channel_get(int fd)
|
||||
{
|
||||
#if NV_FILESYSTEM_ACCESS_AVAILABLE
|
||||
struct file *file;
|
||||
struct inode *inode;
|
||||
int channel = -1;
|
||||
|
||||
file = fget(fd);
|
||||
if (file == NULL)
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
inode = NV_FILE_INODE(file);
|
||||
if (inode == NULL)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Make sure the fd belongs to the nv-caps-imex-drv */
|
||||
if (file->f_op != &g_nv_caps_imex_fops)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* minor number is same as channel */
|
||||
channel = MINOR(inode->i_rdev);
|
||||
|
||||
out:
|
||||
fput(file);
|
||||
|
||||
return channel;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int NV_API_CALL nv_caps_imex_channel_count(void)
|
||||
{
|
||||
return NVreg_ImexChannelCount;
|
||||
}
|
||||
|
||||
static void nv_caps_imex_remove_channel0(void)
|
||||
{
|
||||
if (g_nv_caps_imex_class == NULL)
|
||||
return;
|
||||
|
||||
device_destroy(g_nv_caps_imex_class, g_nv_caps_imex.channel0);
|
||||
|
||||
class_destroy(g_nv_caps_imex_class);
|
||||
|
||||
g_nv_caps_imex_class = NULL;
|
||||
}
|
||||
|
||||
#if defined(NV_CLASS_DEVNODE_HAS_CONST_ARG)
|
||||
static char *nv_caps_imex_devnode(const struct device *dev, umode_t *mode)
|
||||
#else
|
||||
static char *nv_caps_imex_devnode(struct device *dev, umode_t *mode)
|
||||
#endif
|
||||
{
|
||||
if (!mode)
|
||||
return NULL;
|
||||
|
||||
//
|
||||
// Handle only world visible channel0, otherwise let the kernel apply
|
||||
// defaults (root only access)
|
||||
//
|
||||
if (dev->devt == g_nv_caps_imex.channel0)
|
||||
*mode = S_IRUGO | S_IWUGO;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int nv_caps_imex_add_channel0(void)
|
||||
{
|
||||
|
||||
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG)
|
||||
g_nv_caps_imex_class = class_create("nvidia-caps-imex-channels");
|
||||
#else
|
||||
g_nv_caps_imex_class = class_create(THIS_MODULE, "nvidia-caps-imex-channels");
|
||||
#endif
|
||||
|
||||
if (IS_ERR(g_nv_caps_imex_class))
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS, "nv-caps-imex failed to register class.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Install udev callback
|
||||
g_nv_caps_imex_class->devnode = nv_caps_imex_devnode;
|
||||
|
||||
g_nv_caps_imex.dev_channel0 = device_create(g_nv_caps_imex_class, NULL,
|
||||
g_nv_caps_imex.channel0, NULL,
|
||||
"nvidia-caps-imex-channels!channel%d", 0);
|
||||
if (IS_ERR(g_nv_caps_imex.dev_channel0))
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS, "nv-caps-imex failed to create channel0.\n");
|
||||
class_destroy(g_nv_caps_imex_class);
|
||||
g_nv_caps_imex_class = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nv_printf(NV_DBG_ERRORS, "nv-caps-imex channel0 created. "
|
||||
"Make sure you are aware of the IMEX security model.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NV_API_CALL nv_caps_imex_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (g_nv_caps_imex.initialized)
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS, "nv-caps-imex is already initialized.\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
if (NVreg_ImexChannelCount == 0)
|
||||
{
|
||||
nv_printf(NV_DBG_INFO, "nv-caps-imex is disabled.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_nv_caps_imex_class = NULL;
|
||||
g_nv_caps_imex.dev_channel0 = NULL;
|
||||
|
||||
rc = alloc_chrdev_region(&g_nv_caps_imex.channel0, 0,
|
||||
NVreg_ImexChannelCount,
|
||||
"nvidia-caps-imex-channels");
|
||||
if (rc < 0)
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS, "nv-caps-imex failed to create cdev.\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
cdev_init(&g_nv_caps_imex.cdev, &g_nv_caps_imex_fops);
|
||||
|
||||
g_nv_caps_imex.cdev.owner = THIS_MODULE;
|
||||
|
||||
rc = cdev_add(&g_nv_caps_imex.cdev, g_nv_caps_imex.channel0,
|
||||
NVreg_ImexChannelCount);
|
||||
if (rc < 0)
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS, "nv-caps-imex failed to add cdev.\n");
|
||||
goto cdev_add_fail;
|
||||
}
|
||||
|
||||
if (NVreg_CreateImexChannel0 == 1)
|
||||
{
|
||||
rc = nv_caps_imex_add_channel0();
|
||||
if (rc < 0)
|
||||
goto channel0_add_fail;
|
||||
}
|
||||
|
||||
g_nv_caps_imex.initialized = NV_TRUE;
|
||||
|
||||
return 0;
|
||||
|
||||
channel0_add_fail:
|
||||
cdev_del(&g_nv_caps_imex.cdev);
|
||||
|
||||
cdev_add_fail:
|
||||
unregister_chrdev_region(g_nv_caps_imex.channel0, NVreg_ImexChannelCount);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void NV_API_CALL nv_caps_imex_exit(void)
|
||||
{
|
||||
if (!g_nv_caps_imex.initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nv_caps_imex_remove_channel0();
|
||||
|
||||
cdev_del(&g_nv_caps_imex.cdev);
|
||||
|
||||
unregister_chrdev_region(g_nv_caps_imex.channel0, NVreg_ImexChannelCount);
|
||||
|
||||
g_nv_caps_imex.initialized = NV_FALSE;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _NV_CAPS_IMEX_H_
|
||||
#define _NV_CAPS_IMEX_H_
|
||||
|
||||
#include <nv-kernel-interface-api.h>
|
||||
|
||||
int NV_API_CALL nv_caps_imex_init(void);
|
||||
void NV_API_CALL nv_caps_imex_exit(void);
|
||||
int NV_API_CALL nv_caps_imex_channel_get(int fd);
|
||||
int NV_API_CALL nv_caps_imex_channel_count(void);
|
||||
|
||||
#endif /* _NV_CAPS_IMEX_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,350 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
|
||||
#include "os-interface.h"
|
||||
#include "nv-linux.h"
|
||||
|
||||
#if defined(NV_SOC_TEGRA_TEGRA_BPMP_H_PRESENT) || IS_ENABLED(CONFIG_TEGRA_BPMP)
|
||||
#include <soc/tegra/bpmp-abi.h>
|
||||
#endif
|
||||
|
||||
#if IS_ENABLED(CONFIG_TEGRA_BPMP)
|
||||
#include <soc/tegra/bpmp.h>
|
||||
#elif defined(NV_SOC_TEGRA_TEGRA_BPMP_H_PRESENT)
|
||||
#include <soc/tegra/tegra_bpmp.h>
|
||||
#endif // IS_ENABLED(CONFIG_TEGRA_BPMP)
|
||||
|
||||
#if defined NV_DT_BINDINGS_INTERCONNECT_TEGRA_ICC_ID_H_PRESENT
|
||||
#include <dt-bindings/interconnect/tegra_icc_id.h>
|
||||
#endif
|
||||
|
||||
#ifdef NV_LINUX_PLATFORM_TEGRA_MC_UTILS_H_PRESENT
|
||||
#include <linux/platform/tegra/mc_utils.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// IMP requires information from various BPMP and MC driver functions. The
|
||||
// macro below checks that all of the required functions are present.
|
||||
//
|
||||
#define IMP_SUPPORT_FUNCTIONS_PRESENT \
|
||||
(defined(NV_SOC_TEGRA_TEGRA_BPMP_H_PRESENT) || \
|
||||
IS_ENABLED(CONFIG_TEGRA_BPMP)) && \
|
||||
defined(NV_LINUX_PLATFORM_TEGRA_MC_UTILS_H_PRESENT)
|
||||
|
||||
//
|
||||
// Also create a macro to check if all the required ICC symbols are present.
|
||||
// DT endpoints are defined in dt-bindings/interconnect/tegra_icc_id.h.
|
||||
//
|
||||
#define ICC_SUPPORT_FUNCTIONS_PRESENT \
|
||||
defined(NV_DT_BINDINGS_INTERCONNECT_TEGRA_ICC_ID_H_PRESENT)
|
||||
|
||||
/*!
|
||||
* @brief Returns IMP-relevant data collected from other modules
|
||||
*
|
||||
* @param[out] tegra_imp_import_data Structure to receive the data
|
||||
*
|
||||
* @returns NV_OK if successful,
|
||||
* NV_ERR_NOT_SUPPORTED if the functionality is not available.
|
||||
*/
|
||||
NV_STATUS NV_API_CALL
|
||||
nv_imp_get_import_data
|
||||
(
|
||||
TEGRA_IMP_IMPORT_DATA *tegra_imp_import_data
|
||||
)
|
||||
{
|
||||
#if IMP_SUPPORT_FUNCTIONS_PRESENT
|
||||
tegra_imp_import_data->num_dram_channels = get_dram_num_channels();
|
||||
nv_printf(NV_DBG_INFO, "NVRM: num_dram_channels = %u\n",
|
||||
tegra_imp_import_data->num_dram_channels);
|
||||
|
||||
return NV_OK;
|
||||
#else // IMP_SUPPORT_FUNCTIONS_PRESENT
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Tells BPMP whether or not RFL is valid
|
||||
*
|
||||
* Display HW generates an ok_to_switch signal which asserts when mempool
|
||||
* occupancy is high enough to be able to turn off memory long enough to
|
||||
* execute a dramclk frequency switch without underflowing display output.
|
||||
* ok_to_switch drives the RFL ("request for latency") signal in the memory
|
||||
* unit, and the switch sequencer waits for this signal to go active before
|
||||
* starting a dramclk switch. However, if the signal is not valid (e.g., if
|
||||
* display HW or SW has not been initialized yet), the switch sequencer ignores
|
||||
* the signal. This API tells BPMP whether or not the signal is valid.
|
||||
*
|
||||
* @param[in] nv Per GPU Linux state
|
||||
* @param[in] bEnable True if RFL will be valid; false if invalid
|
||||
*
|
||||
* @returns NV_OK if successful,
|
||||
* NV_ERR_NOT_SUPPORTED if the functionality is not available, or
|
||||
* NV_ERR_GENERIC if some other kind of error occurred.
|
||||
*/
|
||||
NV_STATUS NV_API_CALL
|
||||
nv_imp_enable_disable_rfl
|
||||
(
|
||||
nv_state_t *nv,
|
||||
NvBool bEnable
|
||||
)
|
||||
{
|
||||
NV_STATUS status = NV_ERR_NOT_SUPPORTED;
|
||||
#if IMP_SUPPORT_FUNCTIONS_PRESENT
|
||||
#if IS_ENABLED(CONFIG_TEGRA_BPMP) && NV_SUPPORTS_PLATFORM_DEVICE
|
||||
nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
|
||||
struct tegra_bpmp *bpmp = tegra_bpmp_get(nvl->dev);
|
||||
struct tegra_bpmp_message msg;
|
||||
struct mrq_emc_disp_rfl_request emc_disp_rfl_request;
|
||||
int rc;
|
||||
|
||||
memset(&emc_disp_rfl_request, 0, sizeof(emc_disp_rfl_request));
|
||||
emc_disp_rfl_request.mode = bEnable ? EMC_DISP_RFL_MODE_ENABLED :
|
||||
EMC_DISP_RFL_MODE_DISABLED;
|
||||
msg.mrq = MRQ_EMC_DISP_RFL;
|
||||
msg.tx.data = &emc_disp_rfl_request;
|
||||
msg.tx.size = sizeof(emc_disp_rfl_request);
|
||||
msg.rx.data = NULL;
|
||||
msg.rx.size = 0;
|
||||
|
||||
rc = tegra_bpmp_transfer(bpmp, &msg);
|
||||
if (rc == 0)
|
||||
{
|
||||
nv_printf(NV_DBG_INFO,
|
||||
"\"Wait for RFL\" is %s via MRQ_EMC_DISP_RFL\n",
|
||||
bEnable ? "enabled" : "disabled");
|
||||
status = NV_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS,
|
||||
"MRQ_EMC_DISP_RFL failed to %s \"Wait for RFL\" (error code = %d)\n",
|
||||
bEnable ? "enable" : "disable",
|
||||
rc);
|
||||
status = NV_ERR_GENERIC;
|
||||
}
|
||||
#else
|
||||
nv_printf(NV_DBG_ERRORS, "nv_imp_enable_disable_rfl stub called!\n");
|
||||
#endif
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Obtains a handle for the display data path
|
||||
*
|
||||
* If a handle is obtained successfully, it is not returned to the caller; it
|
||||
* is saved for later use by subsequent nv_imp_icc_set_bw calls.
|
||||
* nv_imp_icc_get must be called prior to calling nv_imp_icc_set_bw.
|
||||
*
|
||||
* @param[out] nv Per GPU Linux state
|
||||
*
|
||||
* @returns NV_OK if successful,
|
||||
* NV_ERR_NOT_SUPPORTED if the functionality is not available, or
|
||||
* NV_ERR_GENERIC if some other error occurred.
|
||||
*/
|
||||
NV_STATUS NV_API_CALL
|
||||
nv_imp_icc_get
|
||||
(
|
||||
nv_state_t *nv
|
||||
)
|
||||
{
|
||||
#if ICC_SUPPORT_FUNCTIONS_PRESENT && NV_SUPPORTS_PLATFORM_DEVICE
|
||||
nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
|
||||
NV_STATUS status = NV_OK;
|
||||
|
||||
#if defined(NV_DEVM_ICC_GET_PRESENT)
|
||||
// Needs to use devm_of_icc_get function as per the latest ICC driver
|
||||
nvl->nv_imp_icc_path =
|
||||
devm_of_icc_get(nvl->dev, "read-1");
|
||||
|
||||
if (nvl->nv_imp_icc_path == NULL)
|
||||
{
|
||||
nv_printf(NV_DBG_INFO, "NVRM: devm_of_icc_get failed\n");
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
else if (!IS_ERR(nvl->nv_imp_icc_path))
|
||||
{
|
||||
nvl->is_upstream_icc_path = NV_TRUE;
|
||||
return NV_OK;
|
||||
}
|
||||
//
|
||||
// Till we modify all DTs to have interconnect node specified as per
|
||||
// the latest ICC driver, fallback to older ICC mechanism.
|
||||
//
|
||||
#endif
|
||||
|
||||
nvl->nv_imp_icc_path = NULL;
|
||||
|
||||
#if defined(NV_ICC_GET_PRESENT)
|
||||
struct device_node *np;
|
||||
// Check if ICC is present in the device tree, and enabled.
|
||||
np = of_find_node_by_path("/icc");
|
||||
if (np != NULL)
|
||||
{
|
||||
if (of_device_is_available(np))
|
||||
{
|
||||
// Get the ICC data path.
|
||||
nvl->nv_imp_icc_path =
|
||||
icc_get(nvl->dev, TEGRA_ICC_DISPLAY, TEGRA_ICC_PRIMARY);
|
||||
}
|
||||
of_node_put(np);
|
||||
}
|
||||
#else
|
||||
nv_printf(NV_DBG_ERRORS, "NVRM: icc_get() not present\n");
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
|
||||
if (nvl->nv_imp_icc_path == NULL)
|
||||
{
|
||||
nv_printf(NV_DBG_INFO, "NVRM: icc_get disabled\n");
|
||||
status = NV_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
else if (IS_ERR(nvl->nv_imp_icc_path))
|
||||
{
|
||||
nv_printf(NV_DBG_ERRORS, "NVRM: invalid path = %ld\n",
|
||||
PTR_ERR(nvl->nv_imp_icc_path));
|
||||
nvl->nv_imp_icc_path = NULL;
|
||||
status = NV_ERR_GENERIC;
|
||||
}
|
||||
return status;
|
||||
#else
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Releases the handle obtained by nv_imp_icc_get
|
||||
*
|
||||
* @param[in] nv Per GPU Linux state
|
||||
*/
|
||||
void
|
||||
nv_imp_icc_put
|
||||
(
|
||||
nv_state_t *nv
|
||||
)
|
||||
{
|
||||
#if ICC_SUPPORT_FUNCTIONS_PRESENT
|
||||
nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
|
||||
|
||||
#if defined(NV_DEVM_ICC_GET_PRESENT)
|
||||
//
|
||||
// If devm_of_icc_get API is used for requesting the bandwidth,
|
||||
// it does not require to call put explicitly.
|
||||
//
|
||||
if (nvl->is_upstream_icc_path)
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(NV_ICC_PUT_PRESENT) && NV_SUPPORTS_PLATFORM_DISPLAY_DEVICE
|
||||
if (nvl->nv_imp_icc_path != NULL)
|
||||
{
|
||||
icc_put(nvl->nv_imp_icc_path);
|
||||
}
|
||||
#else
|
||||
nv_printf(NV_DBG_ERRORS, "icc_put() not present\n");
|
||||
#endif
|
||||
|
||||
done:
|
||||
nvl->nv_imp_icc_path = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Allocates a specified amount of ISO memory bandwidth for display
|
||||
*
|
||||
* floor_bw_kbps is the minimum required (i.e., floor) dramclk frequency
|
||||
* multiplied by the width of the pipe over which the display data will travel.
|
||||
* (It is understood that the bandwidth calculated by multiplying the clock
|
||||
* frequency by the pipe width will not be realistically achievable, due to
|
||||
* overhead in the memory subsystem. ICC will not actually use the bandwidth
|
||||
* value, except to reverse the calculation to get the required dramclk
|
||||
* frequency.)
|
||||
*
|
||||
* nv_imp_icc_get must be called prior to calling this function.
|
||||
*
|
||||
* @param[in] nv Per GPU Linux state
|
||||
* @param[in] avg_bw_kbps Amount of ISO memory bandwidth requested
|
||||
* @param[in] floor_bw_kbps Min required dramclk freq * pipe width
|
||||
*
|
||||
* @returns NV_OK if successful,
|
||||
* NV_ERR_INSUFFICIENT_RESOURCES if one of the bandwidth values is too
|
||||
* high, and bandwidth cannot be allocated,
|
||||
* NV_ERR_NOT_SUPPORTED if the functionality is not available, or
|
||||
* NV_ERR_GENERIC if some other kind of error occurred.
|
||||
*/
|
||||
NV_STATUS NV_API_CALL
|
||||
nv_imp_icc_set_bw
|
||||
(
|
||||
nv_state_t *nv,
|
||||
NvU32 avg_bw_kbps,
|
||||
NvU32 floor_bw_kbps
|
||||
)
|
||||
{
|
||||
#if ICC_SUPPORT_FUNCTIONS_PRESENT && NV_SUPPORTS_PLATFORM_DEVICE
|
||||
nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
|
||||
int rc;
|
||||
NV_STATUS status = NV_OK;
|
||||
|
||||
//
|
||||
// avg_bw_kbps can be either ISO bw request or NISO bw request.
|
||||
// Use floor_bw_kbps to make floor requests.
|
||||
//
|
||||
#if defined(NV_ICC_SET_BW_PRESENT)
|
||||
//
|
||||
// nv_imp_icc_path will be NULL on AV + L systems because ICC is disabled.
|
||||
// In this case, skip the allocation call, and just return a success
|
||||
// status.
|
||||
//
|
||||
if (nvl->nv_imp_icc_path == NULL)
|
||||
{
|
||||
return NV_OK;
|
||||
}
|
||||
rc = icc_set_bw(nvl->nv_imp_icc_path, avg_bw_kbps, floor_bw_kbps);
|
||||
#else
|
||||
nv_printf(NV_DBG_ERRORS, "icc_set_bw() not present\n");
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
// A negative return value indicates an error.
|
||||
if (rc == -ENOMEM)
|
||||
{
|
||||
status = NV_ERR_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NV_ERR_GENERIC;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
#else
|
||||
return NV_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "conftest.h"
|
||||
|
||||
#undef TRACE_SYSTEM
|
||||
#define TRACE_SYSTEM nvidia
|
||||
|
||||
#if !defined(_TRACE_NV_REPORT_ERR_H) || defined(TRACE_HEADER_MULTI_READ)
|
||||
#define _TRACE_NV_REPORT_ERR_H
|
||||
|
||||
#include <linux/tracepoint.h>
|
||||
|
||||
TRACE_EVENT(nvidia_dev_xid,
|
||||
|
||||
TP_PROTO(const struct pci_dev *pdev, uint32_t error_code, const char *msg),
|
||||
|
||||
TP_ARGS(pdev, error_code, msg),
|
||||
|
||||
TP_STRUCT__entry(
|
||||
__string(dev, pci_name(pdev))
|
||||
__field (u32, error_code)
|
||||
__string(msg, msg)
|
||||
),
|
||||
|
||||
TP_fast_assign(
|
||||
#if NV_ASSIGN_STR_ARGUMENT_COUNT == 1
|
||||
__assign_str(dev);
|
||||
__assign_str(msg);
|
||||
#else
|
||||
__assign_str(dev, pci_name(pdev));
|
||||
__assign_str(msg, msg);
|
||||
#endif
|
||||
__entry->error_code = error_code;
|
||||
),
|
||||
|
||||
TP_printk("Xid (PCI:%s): %u, %s", __get_str(dev), __entry->error_code, __get_str(msg))
|
||||
);
|
||||
|
||||
#endif // !defined(_TRACE_NV_REPORT_ERR_H) || defined(TRACE_HEADER_MULTI_READ)
|
||||
|
||||
#undef TRACE_INCLUDE_PATH
|
||||
#define TRACE_INCLUDE_PATH .
|
||||
#define TRACE_INCLUDE_FILE nv-tracepoint
|
||||
#include <trace/define_trace.h>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
bool libspdm_aead_gcm_prealloc(void **context);
|
||||
void libspdm_aead_free(void *context);
|
||||
bool libspdm_aead_aes_gcm_encrypt_prealloc(void *context,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
uint8_t *tag_out, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size);
|
||||
bool libspdm_aead_aes_gcm_decrypt_prealloc(void *context,
|
||||
const uint8_t *key, size_t key_size,
|
||||
const uint8_t *iv, size_t iv_size,
|
||||
const uint8_t *a_data, size_t a_data_size,
|
||||
const uint8_t *data_in, size_t data_in_size,
|
||||
const uint8_t *tag, size_t tag_size,
|
||||
uint8_t *data_out, size_t *data_out_size);
|
||||
bool libspdm_check_crypto_backend(void);
|
||||
|
||||
bool libspdm_encode_base64(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen);
|
||||
bool libspdm_decode_base64(const uint8_t *src, uint8_t *dst, size_t srclen, size_t *p_dstlen);
|
||||
bool libspdm_pem_to_der(const uint8_t *pem_cert, uint8_t *der_cert, size_t pem_size, size_t *p_der_size);
|
||||
bool libspdm_der_to_pem(const uint8_t *der_cert, uint8_t *pem_cert, size_t der_size, size_t *p_pem_size);
|
||||
@@ -1,82 +0,0 @@
|
||||
#!/bin/sh
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
# DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
get_compiler_type()
|
||||
{
|
||||
printf "#if defined(__clang__)
|
||||
clang
|
||||
#elif defined(__GNUC__)
|
||||
gcc
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
icc
|
||||
#else
|
||||
unknown
|
||||
#endif" | $1 -E -P -
|
||||
}
|
||||
|
||||
get_original_version()
|
||||
{
|
||||
printf "#if defined(__clang__)
|
||||
__clang_major__ __clang_minor__ __clang_patchlevel__
|
||||
#elif defined(__GNUC__)
|
||||
__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
__INTEL_COMPILER __INTEL_COMPILER_UPDATE
|
||||
#endif" | $1 -E -P -
|
||||
}
|
||||
|
||||
get_canonical_version()
|
||||
{
|
||||
type=$(get_compiler_type $1)
|
||||
set -- $(get_original_version $1)
|
||||
|
||||
# get the version based on the type
|
||||
if [ "$type" = "unknown" ]; then
|
||||
echo >&2 "unknown compiler: bailing out"
|
||||
exit 1
|
||||
elif [ "$type" = "icc" ]; then
|
||||
echo >&2 "icc is not supported"
|
||||
exit 1
|
||||
else
|
||||
major=$1
|
||||
minor=$2
|
||||
fi
|
||||
patch=$3
|
||||
echo $(($3 + $2 * 100 + $1 * 10000))
|
||||
}
|
||||
|
||||
if [ "$1" = "type" ]; then
|
||||
echo $(get_compiler_type $2)
|
||||
elif [ "$1" = "version_is_at_least" ]; then
|
||||
if [ -z "$3" ]; then
|
||||
echo >&2 "minimum compiler version cannot be empty"
|
||||
exit 1
|
||||
fi
|
||||
version=$(get_canonical_version $2)
|
||||
if [ "$version" -gt $(($3-1)) ]; then
|
||||
echo "1"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
# To install the build kernel modules: run (as root) `make modules_install`
|
||||
###########################################################################
|
||||
|
||||
###########################################################################
|
||||
# variables
|
||||
###########################################################################
|
||||
include utils.mk
|
||||
|
||||
all: modules
|
||||
|
||||
nv_kernel_o = src/nvidia/$(OUTPUTDIR)/nv-kernel.o
|
||||
nv_kernel_o_binary = kernel-open/nvidia/nv-kernel.o_binary
|
||||
@@ -16,20 +16,13 @@ nv_kernel_o_binary = kernel-open/nvidia/nv-kernel.o_binary
|
||||
nv_modeset_kernel_o = src/nvidia-modeset/$(OUTPUTDIR)/nv-modeset-kernel.o
|
||||
nv_modeset_kernel_o_binary = kernel-open/nvidia-modeset/nv-modeset-kernel.o_binary
|
||||
|
||||
###########################################################################
|
||||
# rules
|
||||
###########################################################################
|
||||
.PHONY: $(nv_kernel_o) $(nv_modeset_kernel_o) modules modules_install
|
||||
|
||||
include utils.mk
|
||||
|
||||
.PHONY: all
|
||||
all: modules
|
||||
|
||||
###########################################################################
|
||||
# nv-kernel.o is the OS agnostic portion of nvidia.ko
|
||||
###########################################################################
|
||||
|
||||
.PHONY: $(nv_kernel_o)
|
||||
$(nv_kernel_o):
|
||||
$(MAKE) -C src/nvidia
|
||||
|
||||
@@ -41,7 +34,6 @@ $(nv_kernel_o_binary): $(nv_kernel_o)
|
||||
# nv-modeset-kernel.o is the OS agnostic portion of nvidia-modeset.ko
|
||||
###########################################################################
|
||||
|
||||
.PHONY: $(nv_modeset_kernel_o)
|
||||
$(nv_modeset_kernel_o):
|
||||
$(MAKE) -C src/nvidia-modeset
|
||||
|
||||
@@ -54,33 +46,31 @@ $(nv_modeset_kernel_o_binary): $(nv_modeset_kernel_o)
|
||||
# the kernel modules with kbuild.
|
||||
###########################################################################
|
||||
|
||||
.PHONY: modules
|
||||
modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary)
|
||||
$(MAKE) -C kernel-open modules
|
||||
|
||||
|
||||
###########################################################################
|
||||
# Install the built kernel modules using kbuild.
|
||||
###########################################################################
|
||||
|
||||
.PHONY: modules_install
|
||||
modules_install:
|
||||
$(MAKE) -C kernel-open modules_install
|
||||
|
||||
|
||||
###########################################################################
|
||||
# clean
|
||||
###########################################################################
|
||||
|
||||
.PHONY: clean
|
||||
.PHONY: clean nvidia.clean nvidia-modeset.clean kernel-open.clean
|
||||
|
||||
clean: nvidia.clean nvidia-modeset.clean kernel-open.clean
|
||||
|
||||
.PHONY: nvidia.clean
|
||||
nvidia.clean:
|
||||
$(MAKE) -C src/nvidia clean
|
||||
|
||||
.PHONY: nvidia-modeset.clean
|
||||
nvidia-modeset.clean:
|
||||
$(MAKE) -C src/nvidia-modeset clean
|
||||
|
||||
.PHONY: kernel-open.clean
|
||||
kernel-open.clean:
|
||||
$(MAKE) -C kernel-open clean
|
||||
160
nvdisplay/README.md
Normal file
160
nvdisplay/README.md
Normal file
@@ -0,0 +1,160 @@
|
||||
# NVIDIA Linux Open GPU Kernel Module Source
|
||||
|
||||
This is the source release of the NVIDIA Linux open GPU kernel modules,
|
||||
version 35.5.0.
|
||||
|
||||
|
||||
## How to Build
|
||||
|
||||
To build:
|
||||
|
||||
make modules -j`nproc`
|
||||
|
||||
To install, first uninstall any existing NVIDIA kernel modules. Then,
|
||||
as root:
|
||||
|
||||
make modules_install -j`nproc`
|
||||
|
||||
Note that the kernel modules built here must be used with gsp.bin
|
||||
firmware and user-space NVIDIA GPU driver components from a corresponding
|
||||
35.5.0 driver release. This can be achieved by installing
|
||||
the NVIDIA GPU driver from the .run file using the `--no-kernel-modules`
|
||||
option. E.g.,
|
||||
|
||||
sh ./NVIDIA-Linux-[...].run --no-kernel-modules
|
||||
|
||||
|
||||
## Supported Target CPU Architectures
|
||||
|
||||
Currently, the kernel modules can be built for x86_64 or aarch64.
|
||||
If cross-compiling, set these variables on the make command line:
|
||||
|
||||
TARGET_ARCH=aarch64|x86_64
|
||||
CC
|
||||
LD
|
||||
AR
|
||||
CXX
|
||||
OBJCOPY
|
||||
|
||||
E.g.,
|
||||
|
||||
# compile on x86_64 for aarch64
|
||||
make modules -j`nproc` \
|
||||
TARGET_ARCH=aarch64 \
|
||||
CC=aarch64-linux-gnu-gcc \
|
||||
LD=aarch64-linux-gnu-ld \
|
||||
AR=aarch64-linux-gnu-ar \
|
||||
CXX=aarch64-linux-gnu-g++ \
|
||||
OBJCOPY=aarch64-linux-gnu-objcopy
|
||||
|
||||
|
||||
## Other Build Knobs
|
||||
|
||||
NV_VERBOSE - Set this to "1" to print each complete command executed;
|
||||
otherwise, a succinct "CC" line is printed.
|
||||
|
||||
DEBUG - Set this to "1" to build the kernel modules as debug. By default, the
|
||||
build compiles without debugging information. This also enables
|
||||
various debug log messages in the kernel modules.
|
||||
|
||||
These variables can be set on the make command line. E.g.,
|
||||
|
||||
make modules -j`nproc` NV_VERBOSE=1
|
||||
|
||||
|
||||
## Supported Toolchains
|
||||
|
||||
Any reasonably modern version of gcc or clang can be used to build the
|
||||
kernel modules. Note that the kernel interface layers of the kernel
|
||||
modules must be built with the toolchain that was used to build the
|
||||
kernel.
|
||||
|
||||
|
||||
## Supported Linux Kernel Versions
|
||||
|
||||
The NVIDIA open kernel modules support the same range of Linux kernel
|
||||
versions that are supported with the proprietary NVIDIA kernel modules.
|
||||
This is currently Linux kernel 3.10 or newer.
|
||||
|
||||
|
||||
## How to Contribute
|
||||
|
||||
Contributions can be made by creating a pull request on
|
||||
https://github.com/NVIDIA/open-gpu-kernel-modules
|
||||
We'll respond via github.
|
||||
|
||||
Note that when submitting a pull request, you will be prompted to accept
|
||||
a Contributor License Agreement.
|
||||
|
||||
This code base is shared with NVIDIA's proprietary drivers, and various
|
||||
processing is performed on the shared code to produce the source code that is
|
||||
published here. This has several implications for the foreseeable future:
|
||||
|
||||
* The github repo will function mostly as a snapshot of each driver
|
||||
release.
|
||||
|
||||
* We do not expect to be able to provide revision history for individual
|
||||
changes that were made to NVIDIA's shared code base. There will likely
|
||||
only be one git commit per driver release.
|
||||
|
||||
* We may not be able to reflect individual contributions as separate
|
||||
git commits in the github repo.
|
||||
|
||||
* Because the code undergoes various processing prior to publishing here,
|
||||
contributions made here require manual merging to be applied to the shared
|
||||
code base. Therefore, large refactoring changes made here may be difficult to
|
||||
merge and accept back into the shared code base. If you have large
|
||||
refactoring to suggest, please contact in advance, so we can coordinate.
|
||||
|
||||
|
||||
## How to Report Issues
|
||||
|
||||
Any of the existing bug reporting venues can be used to communicate
|
||||
problems to NVIDIA, such as our forum:
|
||||
|
||||
https://forums.developer.nvidia.com/c/gpu-graphics/linux/148
|
||||
|
||||
or linux-bugs@nvidia.com.
|
||||
|
||||
Please see the 'NVIDIA Contact Info and Additional Resources' section
|
||||
of the NVIDIA GPU Driver README for details.
|
||||
|
||||
Please see the separate [SECURITY.md](SECURITY.md) document if you
|
||||
believe you have discovered a security vulnerability in this software.
|
||||
|
||||
|
||||
## Kernel Interface and OS-Agnostic Components of Kernel Modules
|
||||
|
||||
Most of NVIDIA's kernel modules are split into two components:
|
||||
|
||||
* An "OS-agnostic" component: this is the component of each kernel module
|
||||
that is independent of operating system.
|
||||
|
||||
* A "kernel interface layer": this is the component of each kernel module
|
||||
that is specific to the Linux kernel version and configuration.
|
||||
|
||||
When packaged in the NVIDIA .run installation package, the OS-agnostic
|
||||
component is provided as a binary: it is large and time-consuming to
|
||||
compile, so pre-built versions are provided so that the user does
|
||||
not have to compile it during every driver installation. For the
|
||||
nvidia.ko kernel module, this component is named "nv-kernel.o_binary".
|
||||
For the nvidia-modeset.ko kernel module, this component is named
|
||||
"nv-modeset-kernel.o_binary". Neither nvidia-drm.ko nor nvidia-uvm.ko
|
||||
have OS-agnostic components.
|
||||
|
||||
The kernel interface layer component for each kernel module must be built
|
||||
for the target kernel.
|
||||
|
||||
|
||||
## Directory Structure Layout
|
||||
|
||||
- `kernel-open/` The kernel interface layer
|
||||
- `kernel-open/nvidia/` The kernel interface layer for nvidia.ko
|
||||
- `kernel-open/nvidia-drm/` The kernel interface layer for nvidia-drm.ko
|
||||
- `kernel-open/nvidia-modeset/` The kernel interface layer for nvidia-modeset.ko
|
||||
- `kernel-open/nvidia-uvm/` The kernel interface layer for nvidia-uvm.ko
|
||||
|
||||
- `src/` The OS-agnostic code
|
||||
- `src/nvidia/` The OS-agnostic code for nvidia.ko
|
||||
- `src/nvidia-modeset/` The OS-agnostic code for nvidia-modeset.ko
|
||||
- `src/common/` Utility code used by one or more of nvidia.ko and nvidia-modeset.ko
|
||||
@@ -1,8 +1,8 @@
|
||||
# Report a Security Vulnerability
|
||||
|
||||
To report a potential security vulnerability in any NVIDIA product, please use either:
|
||||
* This web form: [Security Vulnerability Submission Form](https://www.nvidia.com/object/submit-security-vulnerability.html), or
|
||||
* Send email to: [NVIDIA PSIRT](mailto:psirt@nvidia.com)
|
||||
* this web form: [Security Vulnerability Submission Form](https://www.nvidia.com/object/submit-security-vulnerability.html), or
|
||||
* send email to: [NVIDIA PSIRT](mailto:psirt@nvidia.com)
|
||||
|
||||
**OEM Partners should contact their NVIDIA Customer Program Manager**
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# NV_KERNEL_SOURCES : The root of the kernel source tree.
|
||||
# NV_KERNEL_OUTPUT : The kernel's output tree.
|
||||
# NV_KERNEL_MODULES : A whitespace-separated list of modules to build.
|
||||
# ARCH : The target CPU architecture: x86_64|arm64
|
||||
# ARCH : The target CPU architecture: x86_64|arm64|powerpc
|
||||
#
|
||||
# Kbuild provides the variables:
|
||||
#
|
||||
@@ -57,106 +57,71 @@ ifeq ($(NV_UNDEF_BEHAVIOR_SANITIZER),1)
|
||||
UBSAN_SANITIZE := y
|
||||
endif
|
||||
|
||||
#
|
||||
# Command to create a symbolic link, explicitly resolving the symlink target
|
||||
# to an absolute path to abstract away the difference between Linux < 6.13,
|
||||
# where the CWD is the Linux kernel source tree for Kbuild extmod builds, and
|
||||
# Linux >= 6.13, where the CWD is the external module source tree.
|
||||
#
|
||||
# This is used to create the nv*-kernel.o -> nv*-kernel.o_binary symlinks for
|
||||
# kernel modules which use precompiled binary object files.
|
||||
#
|
||||
|
||||
quiet_cmd_symlink = SYMLINK $@
|
||||
cmd_symlink = ln -sf $(abspath $<) $@
|
||||
|
||||
|
||||
$(foreach _module, $(NV_KERNEL_MODULES), \
|
||||
$(eval include $(src)/$(_module)/$(_module).Kbuild))
|
||||
|
||||
|
||||
ccflags-y += -I$(src)/common/inc
|
||||
ccflags-y += -I$(src)
|
||||
ccflags-y += -Wall $(DEFINES) $(INCLUDES) -Wno-cast-qual -Wno-format-extra-args
|
||||
ccflags-y += -D__KERNEL__ -DMODULE -DNVRM
|
||||
ccflags-y += -DNV_VERSION_STRING=\"580.00\"
|
||||
#
|
||||
# Define CFLAGS that apply to all the NVIDIA kernel modules. EXTRA_CFLAGS
|
||||
# is deprecated since 2.6.24 in favor of ccflags-y, but we need to support
|
||||
# older kernels which do not have ccflags-y. Newer kernels append
|
||||
# $(EXTRA_CFLAGS) to ccflags-y for compatibility.
|
||||
#
|
||||
|
||||
# Include and link Tegra out-of-tree modules.
|
||||
ifneq ($(wildcard /usr/src/nvidia/nvidia-oot),)
|
||||
SYSSRCNVOOT ?= /usr/src/nvidia/nvidia-oot
|
||||
endif
|
||||
EXTRA_CFLAGS += -I$(src)/common/inc
|
||||
EXTRA_CFLAGS += -I$(src)
|
||||
EXTRA_CFLAGS += -Wall -MD $(DEFINES) $(INCLUDES) -Wno-cast-qual -Wno-error -Wno-format-extra-args
|
||||
EXTRA_CFLAGS += -D__KERNEL__ -DMODULE -DNVRM
|
||||
EXTRA_CFLAGS += -DNV_VERSION_STRING=\"35.5.0\"
|
||||
|
||||
ifneq ($(SYSSRCHOST1X),)
|
||||
ccflags-y += -I$(SYSSRCHOST1X)
|
||||
EXTRA_CFLAGS += -I$(SYSSRCHOST1X)
|
||||
endif
|
||||
|
||||
ifneq ($(SYSSRCNVOOT),)
|
||||
ccflags-y += -I$(SYSSRCNVOOT)/include
|
||||
KBUILD_EXTRA_SYMBOLS = $(SYSSRCNVOOT)/Module.symvers
|
||||
endif
|
||||
|
||||
# Some Android kernels prohibit driver use of filesystem functions like
|
||||
# filp_open() and kernel_read(). Disable the NV_FILESYSTEM_ACCESS_AVAILABLE
|
||||
# functionality that uses those functions when building for Android.
|
||||
|
||||
PLATFORM_IS_ANDROID ?= 0
|
||||
|
||||
ifeq ($(PLATFORM_IS_ANDROID),1)
|
||||
ccflags-y += -DNV_FILESYSTEM_ACCESS_AVAILABLE=0
|
||||
else
|
||||
ccflags-y += -DNV_FILESYSTEM_ACCESS_AVAILABLE=1
|
||||
endif
|
||||
|
||||
ccflags-y += -Wno-unused-function
|
||||
EXTRA_CFLAGS += -Wno-unused-function
|
||||
|
||||
ifneq ($(NV_BUILD_TYPE),debug)
|
||||
ccflags-y += -Wuninitialized
|
||||
EXTRA_CFLAGS += -Wuninitialized
|
||||
endif
|
||||
|
||||
ccflags-y += -fno-strict-aliasing
|
||||
EXTRA_CFLAGS += -fno-strict-aliasing
|
||||
|
||||
ifeq ($(ARCH),arm64)
|
||||
ccflags-y += -mstrict-align
|
||||
EXTRA_CFLAGS += -mstrict-align
|
||||
endif
|
||||
|
||||
ifeq ($(NV_BUILD_TYPE),debug)
|
||||
ccflags-y += -g
|
||||
EXTRA_CFLAGS += -g -gsplit-dwarf
|
||||
endif
|
||||
|
||||
ccflags-y += -ffreestanding
|
||||
EXTRA_CFLAGS += -ffreestanding
|
||||
|
||||
ifeq ($(ARCH),arm64)
|
||||
ccflags-y += -mgeneral-regs-only -march=armv8-a
|
||||
ccflags-y += $(call cc-option,-mno-outline-atomics,)
|
||||
EXTRA_CFLAGS += -mgeneral-regs-only -march=armv8-a
|
||||
EXTRA_CFLAGS += $(call cc-option,-mno-outline-atomics,)
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),x86_64)
|
||||
ccflags-y += -mno-red-zone -mcmodel=kernel
|
||||
EXTRA_CFLAGS += -mno-red-zone -mcmodel=kernel
|
||||
endif
|
||||
|
||||
ccflags-y +=
|
||||
ccflags-y += $(call cc-option,-Werror=undef,)
|
||||
ccflags-y += -DNV_SPECTRE_V2=$(NV_SPECTRE_V2)
|
||||
ccflags-y += -DNV_KERNEL_INTERFACE_LAYER
|
||||
ifeq ($(ARCH),powerpc)
|
||||
EXTRA_CFLAGS += -mlittle-endian -mno-strict-align -mno-altivec
|
||||
endif
|
||||
|
||||
EXTRA_CFLAGS +=
|
||||
EXTRA_CFLAGS += $(call cc-option,-Werror=undef,)
|
||||
EXTRA_CFLAGS += -DNV_SPECTRE_V2=$(NV_SPECTRE_V2)
|
||||
EXTRA_CFLAGS += -DNV_KERNEL_INTERFACE_LAYER
|
||||
|
||||
#
|
||||
# Detect SGI UV systems and apply system-specific optimizations.
|
||||
#
|
||||
|
||||
ifneq ($(wildcard /proc/sgi_uv),)
|
||||
ccflags-y += -DNV_CONFIG_X86_UV
|
||||
EXTRA_CFLAGS += -DNV_CONFIG_X86_UV
|
||||
endif
|
||||
|
||||
ifdef VGX_FORCE_VFIO_PCI_CORE
|
||||
ccflags-y += -DNV_VGPU_FORCE_VFIO_PCI_CORE
|
||||
endif
|
||||
|
||||
WARNINGS_AS_ERRORS ?=
|
||||
ifeq ($(WARNINGS_AS_ERRORS),1)
|
||||
ccflags-y += -Werror
|
||||
else
|
||||
ccflags-y += -Wno-error
|
||||
endif
|
||||
|
||||
#
|
||||
# The conftest.sh script tests various aspects of the target kernel.
|
||||
@@ -182,12 +147,7 @@ NV_CONFTEST_CMD := /bin/sh $(NV_CONFTEST_SCRIPT) \
|
||||
|
||||
NV_CFLAGS_FROM_CONFTEST := $(shell $(NV_CONFTEST_CMD) build_cflags)
|
||||
|
||||
NV_CONFTEST_CFLAGS = $(NV_CFLAGS_FROM_CONFTEST) $(ccflags-y) -fno-pie
|
||||
NV_CONFTEST_CFLAGS += $(filter -std=%,$(KBUILD_CFLAGS))
|
||||
NV_CONFTEST_CFLAGS += $(call cc-disable-warning,pointer-sign)
|
||||
NV_CONFTEST_CFLAGS += $(call cc-option,-fshort-wchar,)
|
||||
NV_CONFTEST_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types,)
|
||||
NV_CONFTEST_CFLAGS += -Wno-error
|
||||
NV_CONFTEST_CFLAGS = $(NV_CFLAGS_FROM_CONFTEST) $(EXTRA_CFLAGS) -fno-pie
|
||||
|
||||
NV_CONFTEST_COMPILE_TEST_HEADERS := $(obj)/conftest/macros.h
|
||||
NV_CONFTEST_COMPILE_TEST_HEADERS += $(obj)/conftest/functions.h
|
||||
@@ -247,25 +207,9 @@ $(obj)/conftest/patches.h: $(NV_CONFTEST_SCRIPT)
|
||||
@mkdir -p $(obj)/conftest
|
||||
@$(NV_CONFTEST_CMD) patch_check > $@
|
||||
|
||||
include $(src)/header-presence-tests.mk
|
||||
|
||||
# Filename to store the define for the header in $(1); this is only consumed by
|
||||
# the rule below that concatenates all of these together.
|
||||
NV_HEADER_PRESENCE_PART = $(addprefix $(obj)/conftest/header_presence/,$(addsuffix .part,$(1)))
|
||||
|
||||
# Define a rule to check the header $(1).
|
||||
define NV_HEADER_PRESENCE_CHECK
|
||||
$$(call NV_HEADER_PRESENCE_PART,$(1)): $$(NV_CONFTEST_SCRIPT) $(obj)/conftest/uts_release
|
||||
@mkdir -p $$(dir $$@)
|
||||
@$$(NV_CONFTEST_CMD) test_kernel_header '$$(NV_CONFTEST_CFLAGS)' '$(1)' > $$@
|
||||
endef
|
||||
|
||||
# Evaluate the rule above for each header in the list.
|
||||
$(foreach header,$(NV_HEADER_PRESENCE_TESTS),$(eval $(call NV_HEADER_PRESENCE_CHECK,$(header))))
|
||||
|
||||
# Concatenate all of the parts into headers.h.
|
||||
$(obj)/conftest/headers.h: $(call NV_HEADER_PRESENCE_PART,$(NV_HEADER_PRESENCE_TESTS))
|
||||
@cat $^ > $@
|
||||
$(obj)/conftest/headers.h: $(NV_CONFTEST_SCRIPT)
|
||||
@mkdir -p $(obj)/conftest
|
||||
@$(NV_CONFTEST_CMD) test_kernel_headers '$(NV_CONFTEST_CFLAGS)' > $@
|
||||
|
||||
clean-dirs := $(obj)/conftest
|
||||
|
||||
@@ -28,7 +28,7 @@ else
|
||||
else
|
||||
KERNEL_UNAME ?= $(shell uname -r)
|
||||
KERNEL_MODLIB := /lib/modules/$(KERNEL_UNAME)
|
||||
KERNEL_SOURCES := $(shell ((test -d $(KERNEL_MODLIB)/source && echo $(KERNEL_MODLIB)/source) || (test -d $(KERNEL_MODLIB)/build/source && echo $(KERNEL_MODLIB)/build/source)) || echo $(KERNEL_MODLIB)/build)
|
||||
KERNEL_SOURCES := $(shell test -d $(KERNEL_MODLIB)/source && echo $(KERNEL_MODLIB)/source || echo $(KERNEL_MODLIB)/build)
|
||||
endif
|
||||
|
||||
KERNEL_OUTPUT := $(KERNEL_SOURCES)
|
||||
@@ -42,83 +42,27 @@ else
|
||||
else
|
||||
KERNEL_UNAME ?= $(shell uname -r)
|
||||
KERNEL_MODLIB := /lib/modules/$(KERNEL_UNAME)
|
||||
# $(filter patter...,text) - Returns all whitespace-separated words in text that
|
||||
# do match any of the pattern words, removing any words that do not match.
|
||||
# Set the KERNEL_OUTPUT only if either $(KERNEL_MODLIB)/source or
|
||||
# $(KERNEL_MODLIB)/build/source path matches the KERNEL_SOURCES.
|
||||
ifneq ($(filter $(KERNEL_SOURCES),$(KERNEL_MODLIB)/source $(KERNEL_MODLIB)/build/source),)
|
||||
ifeq ($(KERNEL_SOURCES), $(KERNEL_MODLIB)/source)
|
||||
KERNEL_OUTPUT := $(KERNEL_MODLIB)/build
|
||||
KBUILD_PARAMS := KBUILD_OUTPUT=$(KERNEL_OUTPUT)
|
||||
endif
|
||||
endif
|
||||
|
||||
# If CC hasn't been set explicitly, check the value of CONFIG_CC_VERSION_TEXT.
|
||||
# Look for the compiler specified there, and use it by default, if found.
|
||||
ifeq ($(origin CC),default)
|
||||
cc_version_text=$(firstword $(shell . $(KERNEL_OUTPUT)/.config; \
|
||||
echo "$$CONFIG_CC_VERSION_TEXT"))
|
||||
|
||||
ifneq ($(cc_version_text),)
|
||||
ifeq ($(shell command -v $(cc_version_text)),)
|
||||
$(warning WARNING: Unable to locate the compiler $(cc_version_text) \
|
||||
from CONFIG_CC_VERSION_TEXT in the kernel configuration.)
|
||||
else
|
||||
CC=$(cc_version_text)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
CC ?= cc
|
||||
LD ?= ld
|
||||
OBJDUMP ?= objdump
|
||||
AWK ?= awk
|
||||
# Bake the following awk program in a string. The program is needed to add C++
|
||||
# to the languages excluded from BTF generation.
|
||||
#
|
||||
# Also, unconditionally return success (0) from the awk program, rather than
|
||||
# propagating pahole's return status (with 'exit system(pahole_cmd)'), to
|
||||
# workaround an DW_TAG_rvalue_reference_type error in
|
||||
# kernel/nvidia-modeset.ko.
|
||||
#
|
||||
# BEGIN {
|
||||
# pahole_cmd = "pahole"
|
||||
# for (i = 1; i < ARGC; i++) {
|
||||
# if (ARGV[i] ~ /--lang_exclude=/) {
|
||||
# pahole_cmd = pahole_cmd sprintf(" %s,c++", ARGV[i])
|
||||
# } else {
|
||||
# pahole_cmd = pahole_cmd sprintf(" %s", ARGV[i])
|
||||
# }
|
||||
# }
|
||||
# system(pahole_cmd)
|
||||
# }
|
||||
PAHOLE_AWK_PROGRAM = BEGIN { pahole_cmd = \"pahole\"; for (i = 1; i < ARGC; i++) { if (ARGV[i] ~ /--lang_exclude=/) { pahole_cmd = pahole_cmd sprintf(\" %s,c++\", ARGV[i]); } else { pahole_cmd = pahole_cmd sprintf(\" %s\", ARGV[i]); } } system(pahole_cmd); }
|
||||
# If scripts/pahole-flags.sh is not present in the kernel tree, add PAHOLE and
|
||||
# PAHOLE_AWK_PROGRAM assignments to PAHOLE_VARIABLES; otherwise assign the
|
||||
# empty string to PAHOLE_VARIABLES.
|
||||
PAHOLE_VARIABLES=$(if $(wildcard $(KERNEL_SOURCES)/scripts/pahole-flags.sh),,"PAHOLE=$(AWK) '$(PAHOLE_AWK_PROGRAM)'")
|
||||
|
||||
ifndef ARCH
|
||||
ARCH := $(shell uname -m | sed -e 's/i.86/i386/' \
|
||||
-e 's/armv[0-7]\w\+/arm/' \
|
||||
-e 's/aarch64/arm64/' \
|
||||
-e 's/riscv64/riscv/' \
|
||||
-e 's/ppc64le/powerpc/' \
|
||||
)
|
||||
endif
|
||||
|
||||
KERNEL_ARCH = $(ARCH)
|
||||
|
||||
ifneq ($(filter $(ARCH),i386 x86_64),)
|
||||
KERNEL_ARCH = x86
|
||||
else
|
||||
ifeq ($(filter $(ARCH),arm64 riscv),)
|
||||
$(error Unsupported architecture $(ARCH))
|
||||
endif
|
||||
endif
|
||||
|
||||
NV_KERNEL_MODULES ?= $(wildcard nvidia nvidia-modeset nvidia-drm)
|
||||
NV_KERNEL_MODULES := $(filter-out $(NV_EXCLUDE_KERNEL_MODULES), \
|
||||
$(NV_KERNEL_MODULES))
|
||||
INSTALL_MOD_DIR ?= kernel/drivers/video
|
||||
|
||||
NV_VERBOSE ?=
|
||||
SPECTRE_V2_RETPOLINE ?= 0
|
||||
|
||||
@@ -130,13 +74,12 @@ else
|
||||
KBUILD_PARAMS += NV_KERNEL_SOURCES=$(KERNEL_SOURCES)
|
||||
KBUILD_PARAMS += NV_KERNEL_OUTPUT=$(KERNEL_OUTPUT)
|
||||
KBUILD_PARAMS += NV_KERNEL_MODULES="$(NV_KERNEL_MODULES)"
|
||||
KBUILD_PARAMS += INSTALL_MOD_DIR="$(INSTALL_MOD_DIR)"
|
||||
KBUILD_PARAMS += INSTALL_MOD_DIR=kernel/drivers/video
|
||||
KBUILD_PARAMS += NV_SPECTRE_V2=$(SPECTRE_V2_RETPOLINE)
|
||||
|
||||
.PHONY: modules module clean clean_conftest modules_install
|
||||
modules clean modules_install:
|
||||
@$(MAKE) "LD=$(LD)" "CC=$(CC)" "OBJDUMP=$(OBJDUMP)" \
|
||||
$(PAHOLE_VARIABLES) $(KBUILD_PARAMS) $@
|
||||
@$(MAKE) "LD=$(LD)" "CC=$(CC)" "OBJDUMP=$(OBJDUMP)" $(KBUILD_PARAMS) $@
|
||||
@if [ "$@" = "modules" ]; then \
|
||||
for module in $(NV_KERNEL_MODULES); do \
|
||||
if [ -x split-object-file.sh ]; then \
|
||||
@@ -156,9 +99,8 @@ else
|
||||
# module symbols on which the Linux kernel's module resolution is dependent
|
||||
# and hence must be used whenever present.
|
||||
|
||||
LD_SCRIPT ?= $(KERNEL_SOURCES)/scripts/module-common.lds \
|
||||
$(KERNEL_SOURCES)/arch/$(KERNEL_ARCH)/kernel/module.lds \
|
||||
$(KERNEL_OUTPUT)/arch/$(KERNEL_ARCH)/module.lds \
|
||||
LD_SCRIPT ?= $(KERNEL_SOURCES)/scripts/module-common.lds \
|
||||
$(KERNEL_SOURCES)/arch/$(ARCH)/kernel/module.lds \
|
||||
$(KERNEL_OUTPUT)/scripts/module.lds
|
||||
NV_MODULE_COMMON_SCRIPTS := $(foreach s, $(wildcard $(LD_SCRIPT)), -T $(s))
|
||||
|
||||
@@ -101,6 +101,13 @@
|
||||
# define NV_ANDROID
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(DceCore) && !defined(NV_DCECORE)
|
||||
# define NV_DCECORE
|
||||
#endif
|
||||
@@ -242,7 +249,7 @@
|
||||
#endif
|
||||
|
||||
/* For verification-only features not intended to be included in normal drivers */
|
||||
#if defined(ENABLE_VERIF_FEATURES)
|
||||
#if defined(NV_MODS) && defined(DEBUG) && !defined(DISABLE_VERIF_FEATURES)
|
||||
#define NV_VERIF_FEATURES
|
||||
#endif
|
||||
|
||||
@@ -342,6 +349,15 @@
|
||||
#define NVOS_IS_INTEGRITY 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(NVCPU_X86)
|
||||
#define NVCPU_IS_X86 1
|
||||
#else
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020-22 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -29,9 +29,17 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/hash.h>
|
||||
|
||||
#if defined(NV_LINUX_STRINGHASH_H_PRESENT)
|
||||
#include <linux/stringhash.h> /* full_name_hash() */
|
||||
#else
|
||||
#include <linux/dcache.h>
|
||||
#endif
|
||||
|
||||
#if (NV_FULL_NAME_HASH_ARGUMENT_COUNT == 3)
|
||||
#define nv_string_hash(_str) full_name_hash(NULL, _str, strlen(_str))
|
||||
#else
|
||||
#define nv_string_hash(_str) full_name_hash(_str, strlen(_str))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This naive hashtable was introduced by commit d9b482c8ba19 (v3.7, 2012-10-31).
|
||||
@@ -83,6 +91,6 @@ static inline void _nv_hash_init(struct hlist_head *ht, unsigned int sz)
|
||||
* @key: the key of the objects to iterate over
|
||||
*/
|
||||
#define nv_hash_for_each_possible(name, obj, member, key) \
|
||||
hlist_for_each_entry(obj, &name[NV_HASH_MIN(key, NV_HASH_BITS(name))], member)
|
||||
nv_hlist_for_each_entry(obj, &name[NV_HASH_MIN(key, NV_HASH_BITS(name))], member)
|
||||
|
||||
#endif // __NV_HASH_H__
|
||||
@@ -27,21 +27,24 @@
|
||||
#include <nv-kernel-interface-api.h>
|
||||
|
||||
// Enums for supported hypervisor types.
|
||||
// New hypervisor type should be added before OS_HYPERVISOR_UNKNOWN
|
||||
// New hypervisor type should be added before OS_HYPERVISOR_CUSTOM_FORCED
|
||||
typedef enum _HYPERVISOR_TYPE
|
||||
{
|
||||
OS_HYPERVISOR_XEN = 0,
|
||||
OS_HYPERVISOR_VMWARE,
|
||||
OS_HYPERVISOR_HYPERV,
|
||||
OS_HYPERVISOR_KVM,
|
||||
OS_HYPERVISOR_PARALLELS,
|
||||
OS_HYPERVISOR_CUSTOM_FORCED,
|
||||
OS_HYPERVISOR_UNKNOWN
|
||||
} HYPERVISOR_TYPE;
|
||||
|
||||
#define CMD_VFIO_WAKE_REMOVE_GPU 1
|
||||
#define CMD_VGPU_VFIO_PRESENT 2
|
||||
#define CMD_VFIO_PCI_CORE_PRESENT 3
|
||||
#define CMD_VGPU_VFIO_WAKE_WAIT_QUEUE 0
|
||||
#define CMD_VGPU_VFIO_INJECT_INTERRUPT 1
|
||||
#define CMD_VGPU_VFIO_REGISTER_MDEV 2
|
||||
#define CMD_VGPU_VFIO_PRESENT 3
|
||||
|
||||
#define MAX_VF_COUNT_PER_GPU 64
|
||||
#define MAX_VF_COUNT_PER_GPU 64
|
||||
|
||||
typedef enum _VGPU_TYPE_INFO
|
||||
{
|
||||
@@ -52,11 +55,16 @@ typedef enum _VGPU_TYPE_INFO
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *vgpuVfioRef;
|
||||
void *waitQueue;
|
||||
void *nv;
|
||||
NvU32 domain;
|
||||
NvU32 bus;
|
||||
NvU32 device;
|
||||
NvU32 return_status;
|
||||
NvU32 *vgpuTypeIds;
|
||||
NvU32 numVgpuTypes;
|
||||
NvU32 domain;
|
||||
NvU8 bus;
|
||||
NvU8 slot;
|
||||
NvU8 function;
|
||||
NvBool is_virtfn;
|
||||
} vgpu_vfio_info;
|
||||
|
||||
typedef struct
|
||||
@@ -84,6 +92,30 @@ typedef enum VGPU_DEVICE_STATE_E
|
||||
NV_VGPU_DEV_IN_USE = 2
|
||||
} VGPU_DEVICE_STATE;
|
||||
|
||||
typedef enum _VMBUS_CMD_TYPE
|
||||
{
|
||||
VMBUS_CMD_TYPE_INVALID = 0,
|
||||
VMBUS_CMD_TYPE_SETUP = 1,
|
||||
VMBUS_CMD_TYPE_SENDPACKET = 2,
|
||||
VMBUS_CMD_TYPE_CLEANUP = 3,
|
||||
} VMBUS_CMD_TYPE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NvU32 request_id;
|
||||
NvU32 page_count;
|
||||
NvU64 *pPfns;
|
||||
void *buffer;
|
||||
NvU32 bufferlen;
|
||||
} vmbus_send_packet_cmd_params;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NvU32 override_sint;
|
||||
NvU8 *nv_guid;
|
||||
} vmbus_setup_cmd_params;
|
||||
|
||||
/*
|
||||
* Function prototypes
|
||||
*/
|
||||
@@ -25,12 +25,14 @@
|
||||
#ifndef NV_IOCTL_NUMA_H
|
||||
#define NV_IOCTL_NUMA_H
|
||||
|
||||
#if defined(NV_LINUX)
|
||||
|
||||
#include <nv-ioctl-numbers.h>
|
||||
|
||||
#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX)
|
||||
#if defined(NV_KERNEL_INTERFACE_LAYER)
|
||||
|
||||
#include <linux/types.h>
|
||||
#elif defined (NV_KERNEL_INTERFACE_LAYER) && defined(NV_BSD)
|
||||
#include <sys/stdint.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -60,7 +62,6 @@ typedef struct nv_ioctl_numa_info
|
||||
uint64_t memblock_size __aligned(8);
|
||||
uint64_t numa_mem_addr __aligned(8);
|
||||
uint64_t numa_mem_size __aligned(8);
|
||||
uint8_t use_auto_online;
|
||||
nv_offline_addresses_t offline_addresses __aligned(8);
|
||||
} nv_ioctl_numa_info_t;
|
||||
|
||||
@@ -79,3 +80,5 @@ typedef struct nv_ioctl_set_numa_status
|
||||
#define NV_IOCTL_NUMA_STATUS_OFFLINE_FAILED 6
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -39,6 +39,5 @@
|
||||
#define NV_ESC_QUERY_DEVICE_INTR (NV_IOCTL_BASE + 13)
|
||||
#define NV_ESC_SYS_PARAMS (NV_IOCTL_BASE + 14)
|
||||
#define NV_ESC_EXPORT_TO_DMABUF_FD (NV_IOCTL_BASE + 17)
|
||||
#define NV_ESC_WAIT_OPEN_COMPLETE (NV_IOCTL_BASE + 18)
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2020-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -104,7 +104,7 @@ typedef struct nv_ioctl_rm_api_version
|
||||
|
||||
#define NV_RM_API_VERSION_CMD_STRICT 0
|
||||
#define NV_RM_API_VERSION_CMD_RELAXED '1'
|
||||
#define NV_RM_API_VERSION_CMD_QUERY '2'
|
||||
#define NV_RM_API_VERSION_CMD_OVERRIDE '2'
|
||||
|
||||
#define NV_RM_API_VERSION_REPLY_UNRECOGNIZED 0
|
||||
#define NV_RM_API_VERSION_REPLY_RECOGNIZED 1
|
||||
@@ -128,9 +128,6 @@ typedef struct nv_ioctl_register_fd
|
||||
|
||||
#define NV_DMABUF_EXPORT_MAX_HANDLES 128
|
||||
|
||||
#define NV_DMABUF_EXPORT_MAPPING_TYPE_DEFAULT 0
|
||||
#define NV_DMABUF_EXPORT_MAPPING_TYPE_FORCE_PCIE 1
|
||||
|
||||
typedef struct nv_ioctl_export_to_dma_buf_fd
|
||||
{
|
||||
int fd;
|
||||
@@ -139,18 +136,10 @@ typedef struct nv_ioctl_export_to_dma_buf_fd
|
||||
NvU32 numObjects;
|
||||
NvU32 index;
|
||||
NvU64 totalSize NV_ALIGN_BYTES(8);
|
||||
NvU8 mappingType;
|
||||
NvBool bAllowMmap;
|
||||
NvHandle handles[NV_DMABUF_EXPORT_MAX_HANDLES];
|
||||
NvU64 offsets[NV_DMABUF_EXPORT_MAX_HANDLES] NV_ALIGN_BYTES(8);
|
||||
NvU64 sizes[NV_DMABUF_EXPORT_MAX_HANDLES] NV_ALIGN_BYTES(8);
|
||||
NvU32 status;
|
||||
} nv_ioctl_export_to_dma_buf_fd_t;
|
||||
|
||||
typedef struct nv_ioctl_wait_open_complete
|
||||
{
|
||||
int rc;
|
||||
NvU32 adapterStatus;
|
||||
} nv_ioctl_wait_open_complete_t;
|
||||
|
||||
#endif
|
||||
@@ -24,14 +24,18 @@
|
||||
#ifndef __NV_KTHREAD_QUEUE_H__
|
||||
#define __NV_KTHREAD_QUEUE_H__
|
||||
|
||||
struct nv_kthread_q;
|
||||
struct nv_kthread_q_item;
|
||||
typedef struct nv_kthread_q nv_kthread_q_t;
|
||||
typedef struct nv_kthread_q_item nv_kthread_q_item_t;
|
||||
#include <linux/types.h> // atomic_t
|
||||
#include <linux/list.h> // list
|
||||
#include <linux/sched.h> // task_struct
|
||||
#include <linux/numa.h> // NUMA_NO_NODE
|
||||
|
||||
typedef void (*nv_q_func_t)(void *args);
|
||||
#include "conftest.h"
|
||||
|
||||
#include "nv-kthread-q-os.h"
|
||||
#if defined(NV_LINUX_SEMAPHORE_H_PRESENT)
|
||||
#include <linux/semaphore.h>
|
||||
#else
|
||||
#include <asm/semaphore.h>
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nv_kthread_q:
|
||||
@@ -86,6 +90,43 @@ typedef void (*nv_q_func_t)(void *args);
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct nv_kthread_q nv_kthread_q_t;
|
||||
typedef struct nv_kthread_q_item nv_kthread_q_item_t;
|
||||
|
||||
typedef void (*nv_q_func_t)(void *args);
|
||||
|
||||
struct nv_kthread_q
|
||||
{
|
||||
struct list_head q_list_head;
|
||||
spinlock_t q_lock;
|
||||
|
||||
// This is a counting semaphore. It gets incremented and decremented
|
||||
// exactly once for each item that is added to the queue.
|
||||
struct semaphore q_sem;
|
||||
atomic_t main_loop_should_exit;
|
||||
|
||||
struct task_struct *q_kthread;
|
||||
};
|
||||
|
||||
struct nv_kthread_q_item
|
||||
{
|
||||
struct list_head q_list_node;
|
||||
nv_q_func_t function_to_run;
|
||||
void *function_args;
|
||||
};
|
||||
|
||||
#if defined(NV_KTHREAD_CREATE_ON_NODE_PRESENT)
|
||||
#define NV_KTHREAD_Q_SUPPORTS_AFFINITY() 1
|
||||
#else
|
||||
#define NV_KTHREAD_Q_SUPPORTS_AFFINITY() 0
|
||||
#endif
|
||||
|
||||
#ifndef NUMA_NO_NODE
|
||||
#define NUMA_NO_NODE (-1)
|
||||
#endif
|
||||
|
||||
#define NV_KTHREAD_NO_NODE NUMA_NO_NODE
|
||||
|
||||
//
|
||||
// The queue must not be used before calling this routine.
|
||||
//
|
||||
@@ -101,12 +142,18 @@ typedef void (*nv_q_func_t)(void *args);
|
||||
//
|
||||
// A short prefix of the qname arg will show up in []'s, via the ps(1) utility.
|
||||
//
|
||||
// The kernel thread stack is preferably allocated on the specified NUMA node,
|
||||
// but fallback to another node is possible because kernel allocators do not
|
||||
// The kernel thread stack is preferably allocated on the specified NUMA node if
|
||||
// NUMA-affinity (NV_KTHREAD_Q_SUPPORTS_AFFINITY() == 1) is supported, but
|
||||
// fallback to another node is possible because kernel allocators do not
|
||||
// guarantee affinity. Note that NUMA-affinity applies only to
|
||||
// the kthread stack. This API does not do anything about limiting the CPU
|
||||
// affinity of the kthread. That is left to the caller.
|
||||
//
|
||||
// On kernels, which do not support NUMA-aware kthread stack allocations
|
||||
// (NV_KTHTREAD_Q_SUPPORTS_AFFINITY() == 0), the API will return -ENOTSUPP
|
||||
// if the value supplied for 'preferred_node' is anything other than
|
||||
// NV_KTHREAD_NO_NODE.
|
||||
//
|
||||
// Reusing a queue: once a queue is initialized, it must be safely shut down
|
||||
// (see "Stopping the queue(s)", below), before it can be reused. So, for
|
||||
// a simple queue use case, the following will work:
|
||||
@@ -124,7 +171,10 @@ int nv_kthread_q_init_on_node(nv_kthread_q_t *q,
|
||||
// This routine is the same as nv_kthread_q_init_on_node() with the exception
|
||||
// that the queue stack will be allocated on the NUMA node of the caller.
|
||||
//
|
||||
int nv_kthread_q_init(nv_kthread_q_t *q, const char *qname);
|
||||
static inline int nv_kthread_q_init(nv_kthread_q_t *q, const char *qname)
|
||||
{
|
||||
return nv_kthread_q_init_on_node(q, qname, NV_KTHREAD_NO_NODE);
|
||||
}
|
||||
|
||||
//
|
||||
// The caller is responsible for stopping all queues, by calling this routine
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2013-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2013-2020 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -73,4 +73,21 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(NV_HLIST_FOR_EACH_ENTRY_ARGUMENT_COUNT)
|
||||
#if NV_HLIST_FOR_EACH_ENTRY_ARGUMENT_COUNT == 3
|
||||
#define nv_hlist_for_each_entry(pos, head, member) \
|
||||
hlist_for_each_entry(pos, head, member)
|
||||
#else
|
||||
#if !defined(hlist_entry_safe)
|
||||
#define hlist_entry_safe(ptr, type, member) \
|
||||
(ptr) ? hlist_entry(ptr, type, member) : NULL
|
||||
#endif
|
||||
|
||||
#define nv_hlist_for_each_entry(pos, head, member) \
|
||||
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member); \
|
||||
pos; \
|
||||
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
|
||||
#endif
|
||||
#endif // NV_HLIST_FOR_EACH_ENTRY_ARGUMENT_COUNT
|
||||
|
||||
#endif // __NV_LIST_HELPERS_H__
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2017-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2017 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -28,12 +28,30 @@
|
||||
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/rwsem.h>
|
||||
#include <linux/sched.h> /* cond_resched */
|
||||
#include <linux/semaphore.h>
|
||||
#include <linux/sched/signal.h> /* signal_pending */
|
||||
#include <linux/sched.h> /* signal_pending, cond_resched */
|
||||
|
||||
#if defined(NV_LINUX_SCHED_SIGNAL_H_PRESENT)
|
||||
#include <linux/sched/signal.h> /* signal_pending for kernels >= 4.11 */
|
||||
#endif
|
||||
|
||||
#if defined(NV_LINUX_SEMAPHORE_H_PRESENT)
|
||||
#include <linux/semaphore.h>
|
||||
#else
|
||||
#include <asm/semaphore.h>
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_RT_FULL)
|
||||
typedef raw_spinlock_t nv_spinlock_t;
|
||||
#define NV_SPIN_LOCK_INIT(lock) raw_spin_lock_init(lock)
|
||||
#define NV_SPIN_LOCK_IRQ(lock) raw_spin_lock_irq(lock)
|
||||
#define NV_SPIN_UNLOCK_IRQ(lock) raw_spin_unlock_irq(lock)
|
||||
#define NV_SPIN_LOCK_IRQSAVE(lock,flags) raw_spin_lock_irqsave(lock,flags)
|
||||
#define NV_SPIN_UNLOCK_IRQRESTORE(lock,flags) raw_spin_unlock_irqrestore(lock,flags)
|
||||
#define NV_SPIN_LOCK(lock) raw_spin_lock(lock)
|
||||
#define NV_SPIN_UNLOCK(lock) raw_spin_unlock(lock)
|
||||
#define NV_SPIN_UNLOCK_WAIT(lock) raw_spin_unlock_wait(lock)
|
||||
#else
|
||||
typedef spinlock_t nv_spinlock_t;
|
||||
#define NV_DEFINE_SPINLOCK(lock) DEFINE_SPINLOCK(lock)
|
||||
#define NV_SPIN_LOCK_INIT(lock) spin_lock_init(lock)
|
||||
#define NV_SPIN_LOCK_IRQ(lock) spin_lock_irq(lock)
|
||||
#define NV_SPIN_UNLOCK_IRQ(lock) spin_unlock_irq(lock)
|
||||
@@ -42,8 +60,22 @@ typedef spinlock_t nv_spinlock_t;
|
||||
#define NV_SPIN_LOCK(lock) spin_lock(lock)
|
||||
#define NV_SPIN_UNLOCK(lock) spin_unlock(lock)
|
||||
#define NV_SPIN_UNLOCK_WAIT(lock) spin_unlock_wait(lock)
|
||||
#endif
|
||||
|
||||
#define NV_INIT_MUTEX(mutex) sema_init(mutex, 1)
|
||||
#if defined(NV_CONFIG_PREEMPT_RT)
|
||||
#define NV_INIT_SEMA(sema, val) sema_init(sema,val)
|
||||
#else
|
||||
#if !defined(__SEMAPHORE_INITIALIZER) && defined(__COMPAT_SEMAPHORE_INITIALIZER)
|
||||
#define __SEMAPHORE_INITIALIZER __COMPAT_SEMAPHORE_INITIALIZER
|
||||
#endif
|
||||
#define NV_INIT_SEMA(sema, val) \
|
||||
{ \
|
||||
struct semaphore __sema = \
|
||||
__SEMAPHORE_INITIALIZER(*(sema), val); \
|
||||
*(sema) = __sema; \
|
||||
}
|
||||
#endif
|
||||
#define NV_INIT_MUTEX(mutex) NV_INIT_SEMA(mutex, 1)
|
||||
|
||||
static inline int nv_down_read_interruptible(struct rw_semaphore *lock)
|
||||
{
|
||||
264
nvdisplay/kernel-open/common/inc/nv-mm.h
Normal file
264
nvdisplay/kernel-open/common/inc/nv-mm.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016-2017 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef __NV_MM_H__
|
||||
#define __NV_MM_H__
|
||||
|
||||
#include "conftest.h"
|
||||
|
||||
#if !defined(NV_VM_FAULT_T_IS_PRESENT)
|
||||
typedef int vm_fault_t;
|
||||
#endif
|
||||
|
||||
/* pin_user_pages
|
||||
* Presence of pin_user_pages() also implies the presence of unpin-user_page().
|
||||
* Both were added in the v5.6-rc1
|
||||
*
|
||||
* pin_user_pages() was added by commit eddb1c228f7951d399240
|
||||
* ("mm/gup: introduce pin_user_pages*() and FOLL_PIN") in v5.6-rc1 (2020-01-30)
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/mm.h>
|
||||
#include <linux/sched.h>
|
||||
#if defined(NV_PIN_USER_PAGES_PRESENT)
|
||||
#define NV_PIN_USER_PAGES pin_user_pages
|
||||
#define NV_UNPIN_USER_PAGE unpin_user_page
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES NV_GET_USER_PAGES
|
||||
#define NV_UNPIN_USER_PAGE put_page
|
||||
#endif // NV_PIN_USER_PAGES_PRESENT
|
||||
|
||||
/* get_user_pages
|
||||
*
|
||||
* The 8-argument version of get_user_pages was deprecated by commit
|
||||
* (2016 Feb 12: cde70140fed8429acf7a14e2e2cbd3e329036653)for the non-remote case
|
||||
* (calling get_user_pages with current and current->mm).
|
||||
*
|
||||
* Completely moved to the 6 argument version of get_user_pages -
|
||||
* 2016 Apr 4: c12d2da56d0e07d230968ee2305aaa86b93a6832
|
||||
*
|
||||
* write and force parameters were replaced with gup_flags by -
|
||||
* 2016 Oct 12: 768ae309a96103ed02eb1e111e838c87854d8b51
|
||||
*
|
||||
* A 7-argument version of get_user_pages was introduced into linux-4.4.y by
|
||||
* commit 8e50b8b07f462ab4b91bc1491b1c91bd75e4ad40 which cherry-picked the
|
||||
* replacement of the write and force parameters with gup_flags
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(NV_GET_USER_PAGES_HAS_ARGS_FLAGS)
|
||||
#define NV_GET_USER_PAGES get_user_pages
|
||||
#elif defined(NV_GET_USER_PAGES_HAS_ARGS_TSK_FLAGS)
|
||||
#define NV_GET_USER_PAGES(start, nr_pages, flags, pages, vmas) \
|
||||
get_user_pages(current, current->mm, start, nr_pages, flags, pages, vmas)
|
||||
#else
|
||||
static inline long NV_GET_USER_PAGES(unsigned long start,
|
||||
unsigned long nr_pages,
|
||||
unsigned int flags,
|
||||
struct page **pages,
|
||||
struct vm_area_struct **vmas)
|
||||
{
|
||||
int write = flags & FOLL_WRITE;
|
||||
int force = flags & FOLL_FORCE;
|
||||
|
||||
#if defined(NV_GET_USER_PAGES_HAS_ARGS_WRITE_FORCE)
|
||||
return get_user_pages(start, nr_pages, write, force, pages, vmas);
|
||||
#else
|
||||
// NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE
|
||||
return get_user_pages(current, current->mm, start, nr_pages, write,
|
||||
force, pages, vmas);
|
||||
#endif // NV_GET_USER_PAGES_HAS_ARGS_WRITE_FORCE
|
||||
}
|
||||
#endif // NV_GET_USER_PAGES_HAS_ARGS_FLAGS
|
||||
|
||||
/* pin_user_pages_remote
|
||||
*
|
||||
* pin_user_pages_remote() was added by commit eddb1c228f7951d399240
|
||||
* ("mm/gup: introduce pin_user_pages*() and FOLL_PIN") in v5.6 (2020-01-30)
|
||||
*
|
||||
* pin_user_pages_remote() removed 'tsk' parameter by commit
|
||||
* 64019a2e467a ("mm/gup: remove task_struct pointer for all gup code")
|
||||
* in v5.9-rc1 (2020-08-11). *
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(NV_PIN_USER_PAGES_REMOTE_PRESENT)
|
||||
#if defined (NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK)
|
||||
#define NV_PIN_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, vmas, locked) \
|
||||
pin_user_pages_remote(NULL, mm, start, nr_pages, flags, pages, vmas, locked)
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES_REMOTE pin_user_pages_remote
|
||||
#endif // NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK
|
||||
#else
|
||||
#define NV_PIN_USER_PAGES_REMOTE NV_GET_USER_PAGES_REMOTE
|
||||
#endif // NV_PIN_USER_PAGES_REMOTE_PRESENT
|
||||
|
||||
/*
|
||||
* get_user_pages_remote() was added by commit 1e9877902dc7
|
||||
* ("mm/gup: Introduce get_user_pages_remote()") in v4.6 (2016-02-12).
|
||||
*
|
||||
* Note that get_user_pages_remote() requires the caller to hold a reference on
|
||||
* the task_struct (if non-NULL and if this API has tsk argument) and the mm_struct.
|
||||
* This will always be true when using current and current->mm. If the kernel passes
|
||||
* the driver a vma via driver callback, the kernel holds a reference on vma->vm_mm
|
||||
* over that callback.
|
||||
*
|
||||
* get_user_pages_remote() write/force parameters were replaced
|
||||
* with gup_flags by commit 9beae1ea8930 ("mm: replace get_user_pages_remote()
|
||||
* write/force parameters with gup_flags") in v4.9 (2016-10-13).
|
||||
*
|
||||
* get_user_pages_remote() added 'locked' parameter by commit 5b56d49fc31d
|
||||
* ("mm: add locked parameter to get_user_pages_remote()") in
|
||||
* v4.10 (2016-12-14).
|
||||
*
|
||||
* get_user_pages_remote() removed 'tsk' parameter by
|
||||
* commit 64019a2e467a ("mm/gup: remove task_struct pointer for
|
||||
* all gup code") in v5.9-rc1 (2020-08-11).
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT)
|
||||
#if defined(NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED)
|
||||
#define NV_GET_USER_PAGES_REMOTE get_user_pages_remote
|
||||
|
||||
#elif defined(NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_LOCKED)
|
||||
#define NV_GET_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, vmas, locked) \
|
||||
get_user_pages_remote(NULL, mm, start, nr_pages, flags, pages, vmas, locked)
|
||||
|
||||
#elif defined(NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS)
|
||||
#define NV_GET_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, vmas, locked) \
|
||||
get_user_pages_remote(NULL, mm, start, nr_pages, flags, pages, vmas)
|
||||
|
||||
#else
|
||||
// NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_WRITE_FORCE
|
||||
static inline long NV_GET_USER_PAGES_REMOTE(struct mm_struct *mm,
|
||||
unsigned long start,
|
||||
unsigned long nr_pages,
|
||||
unsigned int flags,
|
||||
struct page **pages,
|
||||
struct vm_area_struct **vmas,
|
||||
int *locked)
|
||||
{
|
||||
int write = flags & FOLL_WRITE;
|
||||
int force = flags & FOLL_FORCE;
|
||||
|
||||
return get_user_pages_remote(NULL, mm, start, nr_pages, write, force,
|
||||
pages, vmas);
|
||||
}
|
||||
#endif // NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED
|
||||
#else
|
||||
#if defined(NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE)
|
||||
static inline long NV_GET_USER_PAGES_REMOTE(struct mm_struct *mm,
|
||||
unsigned long start,
|
||||
unsigned long nr_pages,
|
||||
unsigned int flags,
|
||||
struct page **pages,
|
||||
struct vm_area_struct **vmas,
|
||||
int *locked)
|
||||
{
|
||||
int write = flags & FOLL_WRITE;
|
||||
int force = flags & FOLL_FORCE;
|
||||
|
||||
return get_user_pages(NULL, mm, start, nr_pages, write, force, pages, vmas);
|
||||
}
|
||||
|
||||
#else
|
||||
#define NV_GET_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, vmas, locked) \
|
||||
get_user_pages(NULL, mm, start, nr_pages, flags, pages, vmas)
|
||||
#endif // NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE
|
||||
#endif // NV_GET_USER_PAGES_REMOTE_PRESENT
|
||||
|
||||
/*
|
||||
* The .virtual_address field was effectively renamed to .address, by these
|
||||
* two commits:
|
||||
*
|
||||
* struct vm_fault: .address was added by:
|
||||
* 2016-12-14 82b0f8c39a3869b6fd2a10e180a862248736ec6f
|
||||
*
|
||||
* struct vm_fault: .virtual_address was removed by:
|
||||
* 2016-12-14 1a29d85eb0f19b7d8271923d8917d7b4f5540b3e
|
||||
*/
|
||||
static inline unsigned long nv_page_fault_va(struct vm_fault *vmf)
|
||||
{
|
||||
#if defined(NV_VM_FAULT_HAS_ADDRESS)
|
||||
return vmf->address;
|
||||
#else
|
||||
return (unsigned long)(vmf->virtual_address);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_read_lock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_read_lock(mm);
|
||||
#else
|
||||
down_read(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_read_unlock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_read_unlock(mm);
|
||||
#else
|
||||
up_read(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_write_lock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_write_lock(mm);
|
||||
#else
|
||||
down_write(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void nv_mmap_write_unlock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
mmap_write_unlock(mm);
|
||||
#else
|
||||
up_write(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int nv_mm_rwsem_is_locked(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
return rwsem_is_locked(&mm->mmap_lock);
|
||||
#else
|
||||
return rwsem_is_locked(&mm->mmap_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline struct rw_semaphore *nv_mmap_get_lock(struct mm_struct *mm)
|
||||
{
|
||||
#if defined(NV_MM_HAS_MMAP_LOCK)
|
||||
return &mm->mmap_lock;
|
||||
#else
|
||||
return &mm->mmap_sem;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // __NV_MM_H__
|
||||
@@ -26,7 +26,8 @@
|
||||
|
||||
#include "nv-linux.h"
|
||||
|
||||
#if (defined(CONFIG_X86_LOCAL_APIC) || defined(NVCPU_AARCH64)) && \
|
||||
#if (defined(CONFIG_X86_LOCAL_APIC) || defined(NVCPU_AARCH64) || \
|
||||
defined(NVCPU_PPC64LE)) && \
|
||||
(defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR))
|
||||
#define NV_LINUX_PCIE_MSI_SUPPORTED
|
||||
#endif
|
||||
@@ -86,6 +87,12 @@ static inline int nv_pci_enable_msix(nv_linux_state_t *nvl, int nvec)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/*
|
||||
* pci_enable_msix_range() replaced pci_enable_msix() in 3.14-rc1:
|
||||
* 2014-01-03 302a2523c277bea0bbe8340312b09507905849ed
|
||||
*/
|
||||
|
||||
#if defined(NV_PCI_ENABLE_MSIX_RANGE_PRESENT)
|
||||
// We require all the vectors we are requesting so use the same min and max
|
||||
rc = pci_enable_msix_range(nvl->pci_dev, nvl->msix_entries, nvec, nvec);
|
||||
if (rc < 0)
|
||||
@@ -93,6 +100,13 @@ static inline int nv_pci_enable_msix(nv_linux_state_t *nvl, int nvec)
|
||||
return NV_ERR_OPERATING_SYSTEM;
|
||||
}
|
||||
WARN_ON(nvec != rc);
|
||||
#else
|
||||
rc = pci_enable_msix(nvl->pci_dev, nvl->msix_entries, nvec);
|
||||
if (rc != 0)
|
||||
{
|
||||
return NV_ERR_OPERATING_SYSTEM;
|
||||
}
|
||||
#endif
|
||||
|
||||
nvl->num_intr = nvec;
|
||||
return NV_OK;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2019 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -27,8 +27,16 @@
|
||||
#include <linux/pci.h>
|
||||
#include "nv-linux.h"
|
||||
|
||||
#define NV_GPU_BAR1 1
|
||||
#define NV_GPU_BAR3 3
|
||||
#if defined(NV_DEV_IS_PCI_PRESENT)
|
||||
#define nv_dev_is_pci(dev) dev_is_pci(dev)
|
||||
#else
|
||||
/*
|
||||
* Non-PCI devices are only supported on kernels which expose the
|
||||
* dev_is_pci() function. For older kernels, we only support PCI
|
||||
* devices, hence returning true to take all the PCI code paths.
|
||||
*/
|
||||
#define nv_dev_is_pci(dev) (true)
|
||||
#endif
|
||||
|
||||
int nv_pci_register_driver(void);
|
||||
void nv_pci_unregister_driver(void);
|
||||
@@ -36,6 +44,5 @@ int nv_pci_count_devices(void);
|
||||
NvU8 nv_find_pci_capability(struct pci_dev *, NvU8);
|
||||
int nvidia_dev_get_pci_info(const NvU8 *, struct pci_dev **, NvU64 *, NvU64 *);
|
||||
nv_linux_state_t * find_pci(NvU32, NvU8, NvU8, NvU8);
|
||||
NvBool nv_pci_is_valid_topology_for_direct_pci(nv_state_t *, struct pci_dev *);
|
||||
NvBool nv_pci_has_common_pci_switch(nv_state_t *nv, struct pci_dev *);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2015-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2015 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -60,21 +60,31 @@ static inline pgprot_t pgprot_modify_writecombine(pgprot_t old_prot)
|
||||
#endif /* !defined(NV_VMWARE) */
|
||||
|
||||
#if defined(NVCPU_AARCH64)
|
||||
extern NvBool nvos_is_chipset_io_coherent(void);
|
||||
/*
|
||||
* Don't rely on the kernel's definition of pgprot_noncached(), as on 64-bit
|
||||
* ARM that's not for system memory, but device memory instead.
|
||||
* ARM that's not for system memory, but device memory instead. For I/O cache
|
||||
* coherent systems, use cached mappings instead of uncached.
|
||||
*/
|
||||
#define NV_PGPROT_UNCACHED(old_prot) \
|
||||
__pgprot_modify((old_prot), PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC))
|
||||
((nvos_is_chipset_io_coherent()) ? \
|
||||
(old_prot) : \
|
||||
__pgprot_modify((old_prot), PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC)))
|
||||
#elif defined(NVCPU_PPC64LE)
|
||||
/* Don't attempt to mark sysmem pages as uncached on ppc64le */
|
||||
#define NV_PGPROT_UNCACHED(old_prot) old_prot
|
||||
#else
|
||||
#define NV_PGPROT_UNCACHED(old_prot) pgprot_noncached(old_prot)
|
||||
#endif
|
||||
|
||||
#define NV_PGPROT_UNCACHED_DEVICE(old_prot) pgprot_noncached(old_prot)
|
||||
#if defined(NVCPU_AARCH64)
|
||||
#if defined(NV_MT_DEVICE_GRE_PRESENT)
|
||||
#define NV_PROT_WRITE_COMBINED_DEVICE (PROT_DEFAULT | PTE_PXN | PTE_UXN | \
|
||||
PTE_ATTRINDX(MT_DEVICE_GRE))
|
||||
#else
|
||||
#define NV_PROT_WRITE_COMBINED_DEVICE (PROT_DEFAULT | PTE_PXN | PTE_UXN | \
|
||||
PTE_ATTRINDX(MT_DEVICE_nGnRE))
|
||||
#endif
|
||||
#define NV_PGPROT_WRITE_COMBINED_DEVICE(old_prot) \
|
||||
__pgprot_modify(old_prot, PTE_ATTRINDX_MASK, NV_PROT_WRITE_COMBINED_DEVICE)
|
||||
#define NV_PGPROT_WRITE_COMBINED(old_prot) NV_PGPROT_UNCACHED(old_prot)
|
||||
@@ -88,13 +98,32 @@ extern NvBool nvos_is_chipset_io_coherent(void);
|
||||
NV_PGPROT_WRITE_COMBINED_DEVICE(old_prot)
|
||||
#define NV_PGPROT_READ_ONLY(old_prot) \
|
||||
__pgprot(pgprot_val((old_prot)) & ~_PAGE_RW)
|
||||
#elif defined(NVCPU_RISCV64)
|
||||
#elif defined(NVCPU_PPC64LE)
|
||||
/*
|
||||
* Some kernels use H_PAGE instead of _PAGE
|
||||
*/
|
||||
#if defined(_PAGE_RW)
|
||||
#define NV_PAGE_RW _PAGE_RW
|
||||
#elif defined(H_PAGE_RW)
|
||||
#define NV_PAGE_RW H_PAGE_RW
|
||||
#else
|
||||
#warning "The kernel does not provide page protection defines!"
|
||||
#endif
|
||||
|
||||
#if defined(_PAGE_4K_PFN)
|
||||
#define NV_PAGE_4K_PFN _PAGE_4K_PFN
|
||||
#elif defined(H_PAGE_4K_PFN)
|
||||
#define NV_PAGE_4K_PFN H_PAGE_4K_PFN
|
||||
#else
|
||||
#undef NV_PAGE_4K_PFN
|
||||
#endif
|
||||
|
||||
#define NV_PGPROT_WRITE_COMBINED_DEVICE(old_prot) \
|
||||
pgprot_writecombine(old_prot)
|
||||
/* Don't attempt to mark sysmem pages as write combined on riscv */
|
||||
#define NV_PGPROT_WRITE_COMBINED(old_prot) old_prot
|
||||
/* Don't attempt to mark sysmem pages as write combined on ppc64le */
|
||||
#define NV_PGPROT_WRITE_COMBINED(old_prot) old_prot
|
||||
#define NV_PGPROT_READ_ONLY(old_prot) \
|
||||
__pgprot(pgprot_val((old_prot)) & ~_PAGE_WRITE)
|
||||
__pgprot(pgprot_val((old_prot)) & ~NV_PAGE_RW)
|
||||
#else
|
||||
/* Writecombine is not supported */
|
||||
#undef NV_PGPROT_WRITE_COMBINED_DEVICE(old_prot)
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2019-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -29,20 +29,12 @@
|
||||
irqreturn_t nvidia_isr (int, void *);
|
||||
irqreturn_t nvidia_isr_kthread_bh (int, void *);
|
||||
|
||||
|
||||
int nv_platform_register_driver(void);
|
||||
void nv_platform_unregister_driver(void);
|
||||
int nv_platform_count_devices(void);
|
||||
int nv_soc_register_irqs(nv_state_t *nv);
|
||||
void nv_soc_free_irqs(nv_state_t *nv);
|
||||
|
||||
#define NV_SUPPORTS_PLATFORM_DEVICE NV_IS_EXPORT_SYMBOL_PRESENT___platform_driver_register
|
||||
|
||||
#if defined(NV_LINUX_PLATFORM_TEGRA_DCE_DCE_CLIENT_IPC_H_PRESENT)
|
||||
#define NV_SUPPORTS_DCE_CLIENT_IPC 1
|
||||
#else
|
||||
#define NV_SUPPORTS_DCE_CLIENT_IPC 0
|
||||
#endif
|
||||
|
||||
#define NV_SUPPORTS_PLATFORM_DISPLAY_DEVICE (NV_SUPPORTS_PLATFORM_DEVICE && NV_SUPPORTS_DCE_CLIENT_IPC)
|
||||
|
||||
#endif
|
||||
@@ -74,8 +74,21 @@ typedef struct file_operations nv_proc_ops_t;
|
||||
__entry; \
|
||||
})
|
||||
|
||||
/*
|
||||
* proc_mkdir_mode exists in Linux 2.6.9, but isn't exported until Linux 3.0.
|
||||
* Use the older interface instead unless the newer interface is necessary.
|
||||
*/
|
||||
#if defined(NV_PROC_REMOVE_PRESENT)
|
||||
# define NV_PROC_MKDIR_MODE(name, mode, parent) \
|
||||
proc_mkdir_mode(name, mode, parent)
|
||||
#else
|
||||
# define NV_PROC_MKDIR_MODE(name, mode, parent) \
|
||||
({ \
|
||||
struct proc_dir_entry *__entry; \
|
||||
__entry = create_proc_entry(name, mode, parent); \
|
||||
__entry; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define NV_CREATE_PROC_DIR(name,parent) \
|
||||
({ \
|
||||
@@ -91,25 +104,17 @@ typedef struct file_operations nv_proc_ops_t;
|
||||
#define NV_PDE_DATA(inode) PDE_DATA(inode)
|
||||
#endif
|
||||
|
||||
#if defined(NV_PROC_REMOVE_PRESENT)
|
||||
# define NV_REMOVE_PROC_ENTRY(entry) \
|
||||
proc_remove(entry);
|
||||
#else
|
||||
# define NV_REMOVE_PROC_ENTRY(entry) \
|
||||
remove_proc_entry(entry->name, entry->parent);
|
||||
#endif
|
||||
|
||||
void nv_procfs_unregister_all(struct proc_dir_entry *entry,
|
||||
struct proc_dir_entry *delimiter);
|
||||
#define NV_DEFINE_SINGLE_PROCFS_FILE_HELPER(name, lock) \
|
||||
static ssize_t nv_procfs_read_lock_##name( \
|
||||
struct file *file, \
|
||||
char __user *buf, \
|
||||
size_t size, \
|
||||
loff_t *ppos \
|
||||
) \
|
||||
{ \
|
||||
int ret; \
|
||||
ret = nv_down_read_interruptible(&lock); \
|
||||
if (ret < 0) \
|
||||
{ \
|
||||
return ret; \
|
||||
} \
|
||||
size = seq_read(file, buf, size, ppos); \
|
||||
up_read(&lock); \
|
||||
return size; \
|
||||
} \
|
||||
\
|
||||
static int nv_procfs_open_##name( \
|
||||
struct inode *inode, \
|
||||
struct file *filep \
|
||||
@@ -122,6 +127,11 @@ typedef struct file_operations nv_proc_ops_t;
|
||||
{ \
|
||||
return ret; \
|
||||
} \
|
||||
ret = nv_down_read_interruptible(&lock); \
|
||||
if (ret < 0) \
|
||||
{ \
|
||||
single_release(inode, filep); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
\
|
||||
@@ -130,6 +140,7 @@ typedef struct file_operations nv_proc_ops_t;
|
||||
struct file *filep \
|
||||
) \
|
||||
{ \
|
||||
up_read(&lock); \
|
||||
return single_release(inode, filep); \
|
||||
}
|
||||
|
||||
@@ -139,7 +150,46 @@ typedef struct file_operations nv_proc_ops_t;
|
||||
static const nv_proc_ops_t nv_procfs_##name##_fops = { \
|
||||
NV_PROC_OPS_SET_OWNER() \
|
||||
.NV_PROC_OPS_OPEN = nv_procfs_open_##name, \
|
||||
.NV_PROC_OPS_READ = nv_procfs_read_lock_##name, \
|
||||
.NV_PROC_OPS_READ = seq_read, \
|
||||
.NV_PROC_OPS_LSEEK = seq_lseek, \
|
||||
.NV_PROC_OPS_RELEASE = nv_procfs_release_##name, \
|
||||
};
|
||||
|
||||
|
||||
#define NV_DEFINE_SINGLE_PROCFS_FILE_READ_WRITE(name, lock, \
|
||||
write_callback) \
|
||||
NV_DEFINE_SINGLE_PROCFS_FILE_HELPER(name, lock) \
|
||||
\
|
||||
static ssize_t nv_procfs_write_##name( \
|
||||
struct file *file, \
|
||||
const char __user *buf, \
|
||||
size_t size, \
|
||||
loff_t *ppos \
|
||||
) \
|
||||
{ \
|
||||
ssize_t ret; \
|
||||
struct seq_file *s; \
|
||||
\
|
||||
s = file->private_data; \
|
||||
if (s == NULL) \
|
||||
{ \
|
||||
return -EIO; \
|
||||
} \
|
||||
\
|
||||
ret = write_callback(s, buf + *ppos, size - *ppos); \
|
||||
if (ret == 0) \
|
||||
{ \
|
||||
/* avoid infinite loop */ \
|
||||
ret = -EIO; \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
\
|
||||
static const nv_proc_ops_t nv_procfs_##name##_fops = { \
|
||||
NV_PROC_OPS_SET_OWNER() \
|
||||
.NV_PROC_OPS_OPEN = nv_procfs_open_##name, \
|
||||
.NV_PROC_OPS_READ = seq_read, \
|
||||
.NV_PROC_OPS_WRITE = nv_procfs_write_##name, \
|
||||
.NV_PROC_OPS_LSEEK = seq_lseek, \
|
||||
.NV_PROC_OPS_RELEASE = nv_procfs_release_##name, \
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 1999-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 1999-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -25,9 +25,13 @@
|
||||
#define _NV_PROTO_H_
|
||||
|
||||
#include "nv-pci.h"
|
||||
#include "nv-register-module.h"
|
||||
|
||||
#include "nv-platform.h"
|
||||
|
||||
|
||||
extern const char *nv_device_name;
|
||||
extern nvidia_module_t nv_fops;
|
||||
|
||||
void nv_acpi_register_notifier (nv_linux_state_t *);
|
||||
void nv_acpi_unregister_notifier (nv_linux_state_t *);
|
||||
@@ -42,7 +46,7 @@ void nv_procfs_remove_gpu (nv_linux_state_t *);
|
||||
|
||||
int nvidia_mmap (struct file *, struct vm_area_struct *);
|
||||
int nvidia_mmap_helper (nv_state_t *, nv_linux_file_private_t *, nvidia_stack_t *, struct vm_area_struct *, void *);
|
||||
int nv_encode_caching (pgprot_t *, NvU32, nv_memory_type_t);
|
||||
int nv_encode_caching (pgprot_t *, NvU32, NvU32);
|
||||
void nv_revoke_gpu_mappings_locked(nv_state_t *);
|
||||
|
||||
NvUPtr nv_vm_map_pages (struct page **, NvU32, NvBool, NvBool);
|
||||
@@ -53,13 +57,15 @@ void nv_free_contig_pages (nv_alloc_t *);
|
||||
NV_STATUS nv_alloc_system_pages (nv_state_t *, nv_alloc_t *);
|
||||
void nv_free_system_pages (nv_alloc_t *);
|
||||
|
||||
void nv_address_space_init_once (struct address_space *mapping);
|
||||
|
||||
int nv_uvm_init (void);
|
||||
void nv_uvm_exit (void);
|
||||
NV_STATUS nv_uvm_suspend (void);
|
||||
NV_STATUS nv_uvm_resume (void);
|
||||
void nv_uvm_notify_start_device (const NvU8 *uuid);
|
||||
void nv_uvm_notify_stop_device (const NvU8 *uuid);
|
||||
NV_STATUS nv_uvm_event_interrupt (const NvU8 *uuid);
|
||||
NV_STATUS nv_uvm_drain_P2P (const NvU8 *uuid);
|
||||
NV_STATUS nv_uvm_resume_P2P (const NvU8 *uuid);
|
||||
|
||||
/* Move these to nv.h once implemented by other UNIX platforms */
|
||||
NvBool nvidia_get_gpuid_list (NvU32 *gpu_ids, NvU32 *gpu_count);
|
||||
@@ -85,11 +91,8 @@ void nv_shutdown_adapter(nvidia_stack_t *, nv_state_t *, nv_linux_state
|
||||
void nv_dev_free_stacks(nv_linux_state_t *);
|
||||
NvBool nv_lock_init_locks(nvidia_stack_t *, nv_state_t *);
|
||||
void nv_lock_destroy_locks(nvidia_stack_t *, nv_state_t *);
|
||||
int nv_linux_add_device_locked(nv_linux_state_t *);
|
||||
void nv_linux_add_device_locked(nv_linux_state_t *);
|
||||
void nv_linux_remove_device_locked(nv_linux_state_t *);
|
||||
NvBool nv_acpi_power_resource_method_present(struct pci_dev *);
|
||||
|
||||
int nv_linux_init_open_q(nv_linux_state_t *);
|
||||
void nv_linux_stop_open_q(nv_linux_state_t *);
|
||||
|
||||
#endif /* _NV_PROTO_H_ */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2012-2013 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
@@ -21,27 +21,35 @@
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __DETECT_SELF_HOSTED_H__
|
||||
#define __DETECT_SELF_HOSTED_H__
|
||||
|
||||
#ifndef _NV_REGISTER_MODULE_H_
|
||||
#define _NV_REGISTER_MODULE_H_
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/poll.h>
|
||||
|
||||
static inline int pci_devid_is_self_hosted_hopper(unsigned short devid)
|
||||
{
|
||||
return devid >= 0x2340 && devid <= 0x237f; // GH100 Self-Hosted
|
||||
}
|
||||
#include "nvtypes.h"
|
||||
|
||||
static inline int pci_devid_is_self_hosted_blackwell(unsigned short devid)
|
||||
{
|
||||
return (devid >= 0x2940 && devid <= 0x297f) // GB100 Self-Hosted
|
||||
|| (devid >= 0x31c0 && devid <= 0x31ff); // GB110 Self-Hosted
|
||||
}
|
||||
typedef struct nvidia_module_s {
|
||||
struct module *owner;
|
||||
|
||||
static inline int pci_devid_is_self_hosted(unsigned short devid)
|
||||
{
|
||||
return pci_devid_is_self_hosted_hopper(devid) ||
|
||||
pci_devid_is_self_hosted_blackwell(devid)
|
||||
;
|
||||
}
|
||||
/* nvidia0, nvidia1 ..*/
|
||||
const char *module_name;
|
||||
|
||||
/* module instance */
|
||||
NvU32 instance;
|
||||
|
||||
/* file operations */
|
||||
int (*open)(struct inode *, struct file *filp);
|
||||
int (*close)(struct inode *, struct file *filp);
|
||||
int (*mmap)(struct file *filp, struct vm_area_struct *vma);
|
||||
int (*ioctl)(struct inode *, struct file * file, unsigned int cmd, unsigned long arg);
|
||||
unsigned int (*poll)(struct file * file, poll_table *wait);
|
||||
|
||||
} nvidia_module_t;
|
||||
|
||||
int nvidia_register_module(nvidia_module_t *);
|
||||
int nvidia_unregister_module(nvidia_module_t *);
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user