summaryrefslogtreecommitdiff
path: root/lib/rsa
AgeCommit message (Collapse)Author
2026-03-27treewide: fix uImage.FIT document pathsDaniel Golle
Commit 488445cefa1 ("doc: Move FIT into its own directory") moved the documentation in doc/uImage.FIT to doc/usage/fit, subsequently all documents and example sources have been converted to reStructuredText. Fix (almost) all of the remaining occurrences of the old path and filenames across the tree. The exception is doc/uImage.FIT/command_syntax_extensions.txt which apparently has been removed entirely, or at least I was unable to locate where that document is now. Signed-off-by: Daniel Golle <[email protected]>
2025-12-16lib: rsa: use FIT_ALGO_PROP constant instead of "algo" in FITQuentin Schulz
Some FIT image properties have their string represented in include/image.h via constants. FIT_ALGO_PROP does exist and would fit the bill so let's use it instead of using a hardcoded string. Signed-off-by: Quentin Schulz <[email protected]>
2025-11-11Merge patch series "rsa: fix dependency, rename and relocate RSASSA PSS symbols"Tom Rini
Quentin Schulz <[email protected]> says: While historically signature verification is mostly done for FIT such FIT_SIGNATURE dependency for signature algorithm makes sense, it isn't the only kind of file we can verify signatures of. It can also be done manually with rsa_verify_hash() with an embedded public key. Considering the impacted code is guarded by RSA_VERIFY, let's make the symbol depend on that otherwise selecting it without RSA_VERIFY won't do anything. The FIT_SIGNATURE dependency wasn't also enough before as it only implied RSA_VERIFY. Then, simply relocate the RSA SSA PSS padding with the other RSA symbols in lib/rsa instead of in boot/ and rename it to remove the mention to FIT. Finally, add the PSS padding wherever PKCS1.5 padding is specified as one or the other can be used. Link: https://lore.kernel.org/r/[email protected]
2025-11-11rsa: update doxygen doc for RSA signature verification to mention PSSQuentin Schulz
While the verification step originally only supported PKCS1.5 as padding algorithm for the signature, it was later extended to add support for PSS but the doxygen doc wasn't updated to reflect that so let's fix that oversight. Fixes: 061daa0b61f0 ("rsa: add support of padding pss") Signed-off-by: Quentin Schulz <[email protected]>
2025-11-11rsa: rename FIT_RSASSA_PSS to RSASSA_PSS and move symbols under lib/rsaQuentin Schulz
This renames FIT_RSASSA_PSS symbols to drop the FIT_ prefix to avoid potential confusion since there's nothing FIT specific to those symbols. It also isn't really related to booting, so boot/Kconfig is an odd place for them to live. Since they make sense only in relation with RSA, simply move them to lib/rsa where it makes more sense for them to reside. Signed-off-by: Quentin Schulz <[email protected]>
2025-11-06rsa: fix typo in $(PHASE_)RSA_VERIFY_WITH_PKEY help textQuentin Schulz
Signed-off-by: Quentin Schulz <[email protected]>
2025-07-08lib/rsa: allow matching pkcs11 path by object idTobias Olausson
The object= part matches against the label that the pkcs11 token uses for that object, but in some cases, specifically with a Yubikey using ykcs11, where the keys have been imported, the labels differ between the private and public keys [1], making the object= matching useless. These keys will have the same id however, so matching against that works for both the private and public part. [1]: https://github.com/Yubico/yubico-piv-tool/blob/master/doc/YKCS11/Functions_and_values.adoc#key-alias-per-slot-and-object-type Signed-off-by: Tobias Olausson <[email protected]>
2025-06-22lib: rsa: fix compilation error without opensslShiji Yang
The symbol TOOLS_IMAGE_PRE_LOAD doesn't depend on TOOLS_LIBCRYPTO. If we choose to build tools without openssl, rsa_verify_openssl() will attempt to call the unavailable openssl library functions. Fixes: 942c8c8e6697 ("rsa: Add rsa_verify_openssl() to use openssl for host builds") Signed-off-by: Shiji Yang <[email protected]>
2025-03-13lib: rsa: add NULL check for 'algo' inAnton Moryakov
- Check return value of fdt_getprop for NULL. - Return -EFAULT if 'algo' property is missing. - Prevent NULL pointer dereference in strcmp." Triggers found by static analyzer Svace. Signed-off-by: Anton Moryakov <[email protected]>
2025-02-28rsa: Add rsa_verify_openssl() to use openssl for host buildsPaul HENRYS
rsa_verify_openssl() is used in lib/rsa/rsa-verify.c to authenticate data when building host tools. Signed-off-by: Paul HENRYS <[email protected]>
2024-11-14lib: rsa: Set conventional salt length RSA-PSS parameterLoic Poulain
RFC 3447 says that Typical salt length are either 0 or the length of the output of the digest algorithm, RFC 4055 also recommends hash value length as the salt length. Moreover, By convention, most of the signing infrastructures/libraries use the length of the digest algorithm (such as google cloud kms: https://cloud.google.com/kms/docs/algorithms). If the salt-length parameter is not set, openssl default to the maximum allowed value, which is a openssl 'specificity', so this works well for local signing, but restricts compatibility with other engines (e.g pkcs11/libkmsp11): ``` returning 0x71 from C_SignInit due to status INVALID_ARGUMENT: at rsassa_pss.cc:53: expected salt length for key XX is 32, but 478 was supplied in the parameters Could not obtain signature: error:41000070:PKCS#11 module::Mechanism invalid ``` To improve compatibility, we set the default RSA-PSS salt-length value to the conventional one. A further improvement could consist in making it configurable as signature FIT node attribute. rfc3447: https://datatracker.ietf.org/doc/html/rfc3447 rfc4055: https://datatracker.ietf.org/doc/html/rfc4055 Signed-off-by: Loic Poulain <[email protected]>
2024-10-11global: Rename SPL_TPL_ to PHASE_Simon Glass
Use PHASE_ as the symbol to select a particular XPL build. This means that SPL_TPL_ is no-longer set. Update the comment in bootstage to refer to this symbol, instead of SPL_ Signed-off-by: Simon Glass <[email protected]>
2024-04-10lib: add missing line breaks in debug messagesMaxim Moskalets
Add missing line breaks to improve debug log readability. Signed-off-by: Maxim Moskalets <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]>
2024-01-18lib: rsa: Allow legacy URI specification without "pkcs11:"Csókás Bence
But emit a warning for it. Then we can remove support when everyone had time to update their scripts, docs, CI etc. Fixes: ece85cc020 rsa: use pkcs11 uri as defined in rfc7512 Signed-off-by: Csókás Bence <[email protected]>
2024-01-18lib: rsa: Fix PKCS11 URI if one is not given in `keydir`Csókás Bence
If `keydir` is not present, we need to build a PKCS11 URI from just the key name. In this case, we *do* need 'pkcs11:' Fixes: ece85cc020 rsa: use pkcs11 uri as defined in rfc7512 Signed-off-by: Csókás Bence <[email protected]>
2023-12-21lib: rsa: Print detailed error info in rsa_engine_init() on engine ↵Csókás Bence
resolution failure Signed-off-by: Csókás Bence <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2023-12-21lib: Remove <common.h> inclusion from these filesTom Rini
After some header file cleanups to add missing include files, remove common.h from all files in the lib directory. This primarily means just dropping the line but in a few cases we need to add in other header files now. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2023-12-21global: Restrict use of '#include <linux/kconfig.h>'Tom Rini
In general terms, we -include include/linux/kconfig.h and so normal U-Boot code does not need to also #include it. However, for code which is shared with userspace we may need to add it so that either our full config is available or so that macros such as CONFIG_IS_ENABLED() can be evaluated. In this case make sure that we guard these includes with a test for USE_HOSTCC so that it clear as to why we're doing this. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2023-12-20rsa: use pkcs11 uri as defined in rfc7512Ayoub Zaki
pkcs11 : change engine uri to use full pk11-URI as defined in: https://www.rfc-editor.org/rfc/rfc7512.html Signed-off-by: Ayoub Zaki <[email protected]>
2023-01-11lib: rsa: cosmetic: fix building warningHaijun Qin
add initialization of variable 'node',this can aviod the building warning: 'node' may be used uninitialized [-Wmaybe-uninitialized] Signed-off-by: Haijun Qin <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-12-23rsa-verify: Rework host check for CONFIG_RSA_VERIFY_WITH_PKEYTom Rini
While we do not want to use CONFIG_RSA_VERIFY_WITH_PKEY on the host, we cannot undef the symbol in this manner. As this ends up being a test within another function we can use !tools_build() as a test here. Cc: AKASHI Takahiro <[email protected]> Cc: Simon Glass <[email protected]> Signed-off-by: Tom Rini <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-09-15lib: rsa: fix padding_pss_verifyHeinrich Schuchardt
Check the that the hash length is shorter than the message length. This avoids: ./tools/../lib/rsa/rsa-verify.c:275:11: warning: ‘*db’ may be used uninitialized [-Wmaybe-uninitialized] 275 | db[0] &= 0xff >> leftmost_bits; Fixes: 061daa0b61f0 ("rsa: add support of padding pss") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-07-07spl: Ensure all SPL symbols in Kconfig have some SPL dependencyTom Rini
Tighten up symbol dependencies in a number of places. Ensure that a SPL specific option has at least a direct dependency on SPL. In places where it's clear that we depend on something more specific, use that dependency instead. This means in a very small number of places we can drop redundant dependencies. Reported-by: Pali Rohár <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2022-04-11lib: rsa: Update function padding_pss_verify (any-salt)SESA644425
Modify function to support any salt length instead of max length only. Function now detects salt length by parsing the content of db buffer. Note that it works with (but is not limited to) zero-length, digest-length and max-length Signed-off-by: SESA644425 <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-04-11lib: rsa: Leverage existing data buffer instead of systematic copySESA644425
Prior to introduction of modifications in rsassa_pss functions related to padding verification, doing a pass to reduce memory consumption of function by replacing memory copies of parts of const buffer by pointers to the original buffer (masked_db and h are subparts of msg buffer which is declared const, salt is a subpart of db which is a working buffer, unmodified after being filled). New pointers scope is limited to the function where they are declared (not returned to caller by any mean), zeroing risk of memory fault related to the change. Signed-off-by: SESA644425 <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-04-11lib: rsa: Fix const-correctness of rsassa_pss functionsSESA644425
Prior to introduction of modifications in rsassa_pss functions related to padding verification, doing a pass to update const-correctness in targeted functions to comply with coding-rules and avoid const-cast Signed-off-by: SESA644425 <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-03-31lib: rsa: allow rsa verify with pkey in SPLPhilippe Reynes
This commit adds the option SPL_RSA_VERIFY_WITH_PKEY. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Philippe Reynes <[email protected]>
2022-03-04lib: rsa: use actual OpenSSL 1.1.0 EVP MD APIYann Droneaud
Since OpenSSL 1.1.0, EVP_MD_CTX_create() is EVP_MD_CTX_new() EVP_MD_CTX_destroy() is EVP_MD_CTX_free() EVP_MD_CTX_init() is EVP_MD_CTX_reset() As there's no need to reset a newly created EVP_MD_CTX, moreover EVP_DigestSignInit() does the reset, thus call to EVP_MD_CTX_init() can be dropped. As there's no need to reset an EVP_MD_CTX before it's destroyed, as it will be reset by EVP_MD_CTX_free(), call to EVP_MD_CTX_reset() is not needed and can be dropped. Signed-off-by: Yann Droneaud <[email protected]>
2022-01-28rsa: adds rsa3072 algorithmJamin Lin
Add to support rsa 3072 bits algorithm in tools for image sign at host side and adds rsa 3072 bits verification in the image binary. Add test case in vboot for sha384 with rsa3072 algorithm testing. Signed-off-by: Jamin Lin <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2022-01-26image: Return destination node for add_verify_data() methodSimon Glass
It is useful to know where the verification data was written. Update the API to return this. Signed-off-by: Simon Glass <[email protected]>
2022-01-26rsa: Add debugging for failure casesSimon Glass
Add some more debugging to make it easier to see what is being tried and what fails. Fix a few comment styles while here. Signed-off-by: Simon Glass <[email protected]>
2022-01-19doc: replace @return by Return:Heinrich Schuchardt
Sphinx expects Return: and not @return to indicate a return value. find . -name '*.c' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; find . -name '*.h' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; Signed-off-by: Heinrich Schuchardt <[email protected]>
2022-01-10Merge branch 'next'Tom Rini
Signed-off-by: Tom Rini <[email protected]>
2022-01-10lib/rsa: avoid -Wdiscarded-qualifiersHeinrich Schuchardt
The return type of EVP_PKEY_get0_RSA() is const struct rsa_st *. Our code drops the const qualifier leading to In file included from tools/lib/rsa/rsa-sign.c:1: ./tools/../lib/rsa/rsa-sign.c: In function ‘rsa_add_verify_data’: ./tools/../lib/rsa/rsa-sign.c:631:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 631 | rsa = EVP_PKEY_get0_RSA(pkey); | ^ Add a type conversion. Signed-off-by: Heinrich Schuchardt <[email protected]>
2022-01-09Merge tag 'u-boot-amlogic-20220107' of ↵Tom Rini
https://source.denx.de/u-boot/custodians/u-boot-amlogic into next - disable CONFIG_NET_RANDOM_ETHADDR when unnecessary on amlogic based configs - meson64_android: add board specific env settings, in order to support VIM3/L for android - add changes to support VIM3/L android boot by using meson64_android.h config
2021-12-26tools: avoid OpenSSL deprecation warningsHeinrich Schuchardt
Our Gitlab CI buildsystem is set up to treat warnings as errors. With OpenSSL 3.0 a lot of deprecation warnings occur. With the patch compatibility with OpenSSL 1.1.1 is declared. In the long run we should upgrade our code to use the current API. A -Wdiscarded-qualifiers warning is muted by casting. Signed-off-by: Heinrich Schuchardt <[email protected]>
2021-11-17crypto: aspeed: Add AST2600 ACRY supportChia-Wei Wang
ACRY is designed to accelerate ECC/RSA digital signature generation and verification. Signed-off-by: Chia-Wei Wang <[email protected]>
2021-10-26lib: rsa: rsa-verify: also check that padding is not NULLPhilippe Reynes
This commit adds a check on the padding in the function rsa_verify_key to avoid using a NULL pointer. Signed-off-by: Philippe Reynes <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-10-20Merge tag 'u-boot-imx-20211020' of ↵Tom Rini
https://source.denx.de/u-boot/custodians/u-boot-imx u-boot-imx-20211020 ------------------- First PR from u-boot-imx for 2022.01 CI: https://source.denx.de/u-boot/custodians/u-boot-imx/-/pipelines/9535 - new board: kontron-sl-mx8mm - imx8m: - fix secure boot - imx ESDHC: fixes - i.MX53: Support thum2, bmode and fixes for Menlo board usbarmory switch to Ethernet driver model - imx6 : - DDR calibration for Toradex boards - imx7: - Fixes - Updated gateworks boards (ventana / venice) # gpg verification failed.
2021-10-08image: Use Kconfig to enable FIT_RSASSA_PSS on hostSimon Glass
Add a host Kconfig for FIT_RSASSA_PSS. With this we can use CONFIG_IS_ENABLED(FIT_RSASSA_PSS) directly in the host build, so drop the forcing of this in the image.h header. Drop the #ifdef around padding_pss_verify() too since it is not needed. Use the compiler to check the config where possible, instead of the preprocessor. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Alexandru Gagniuc <[email protected]>
2021-10-07Kconfig: Don't use RSA_FREESCALE_EXP on MX7ULPRicardo Salveti
The CAAM on IMX7ULP doesn't support public key hardware acceleration (PKHA), as in other NXP parts. Disable RSA_FREESCALE_EXP for IMX7ULP too. Fixed: f4e9ff7135 ("Kconfig: Don't use RSA_FREESCALE_EXP on IMX") Signed-off-by: Ricardo Salveti <[email protected]> Signed-off-by: Oleksandr Suvorov <[email protected]>
2021-10-06lib: rsa: fix dependency for SPL_RSA_VERIFYOleksandr Suvorov
SPL_RSA_VERIFY requires SPL_RSA to be enabled. Add correct dependency. Signed-off-by: Oleksandr Suvorov <[email protected]>
2021-09-16Merge tag 'v2021.10-rc4' into nextTom Rini
Prepare v2021.10-rc4 Signed-off-by: Tom Rini <[email protected]> # gpg: Signature made Tue 14 Sep 2021 06:58:32 PM EDT # gpg: using RSA key 1A3C7F70E08FAB1707809BBF147C39FF9634B72C # gpg: Good signature from "Thomas Rini <[email protected]>" [ultimate] # Conflicts: # board/Arcturus/ucp1020/spl.c # cmd/mvebu/Kconfig # common/Kconfig.boot # common/image-fit.c # configs/UCP1020_defconfig # configs/sifive_unmatched_defconfig # drivers/pci/Kconfig # include/configs/UCP1020.h # include/configs/sifive-unmatched.h # lib/Makefile # scripts/config_whitelist.txt
2021-09-14image: rsa: Move padding_algos to linker listsAlexandru Gagniuc
We are not guaranteed to have the padding_pkcs_15_verify symbol since commit 92c960bc1d ("lib: rsa: Remove #ifdefs from rsa.h"), and commit 61416fe9df ("Kconfig: FIT_SIGNATURE should not select RSA_VERIFY") The padding_algos only make sense with RSA verification, which can now be disabled in lieu of ECDSA. In fact this will lead to build failures because of the missing symbol mentioned earlier. To resolve this, move the padding_algos to a linker list, with declarations moved to rsa_verify.c. This is consistent with commit 6909edb4ce ("image: rsa: Move verification algorithm to a linker list") One could argue that the added #ifdef USE_HOSTCC is ugly, and should be hidden within the U_BOOT_PADDING_ALGO() macro. However, this would be inconsistent with the "cryptos" list. This logic for was not previously explored: Without knowledge of the U_BOOT_PADDING_ALGO() macro, its use is similar to something being declared. However, should #ifndef USE_HOSTCC be part of the macro, it would not be obvious that it behaves differently on host code and target code. Having the #ifndef outside the macro makes this obvious. Also, the #ifdef is not always necessary. For example ecda-verify makes use of U_BOOT_CRYPTO_ALGO() without any accompanying #ifdefs. The fundamental issue is a lack of separation of host and target code in rsa_verify. Therefore, the declaration of a padding algo with the external #ifdef is more readable and consistent. Signed-off-by: Alexandru Gagniuc <[email protected]>
2021-09-14lib/rsa: don't use NULL as key_idHeinrich Schuchardt
If keydir is not provided but name is we want to use name as key_id. But with the current coding name is only used on its own if it is NULL and keydir is provided which never occurs. Fixes: 824ee745fbca ("lib/rsa: Use the 'keyfile' argument from mkimage") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-09-01lib: -Wformat-truncation in rsa_engine_get_priv_keyHeinrich Schuchardt
With glibc 2.33 (Ubuntu package glibc6 2.33-0ubuntu9) building sifive_unmatched_defconfig results in: In file included from /usr/include/stdio.h:866, from ././include/compiler.h:26, from <command-line>: In function ‘snprintf’, inlined from ‘rsa_engine_get_priv_key’ at ./tools/../^:273:4: /usr/include/riscv64-linux-gnu/bits/stdio2.h:71:10: warning: ‘%s’ directive argument is null [-Wformat-truncation=] 71 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ Avoid passing a NULL string. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-09-01lib/rsa: Remove support for OpenSSL < 1.1.0 and libressl < 2.7.0Alexandru Gagniuc
Older OpenSSL and libressl versions have a slightly different API. This require #ifdefs to support. However, we still can't support it because the ECDSA path does not compile with these older versions. These #ifdefs are truly a vestigial appendage. Alternatively, the ECDSA path could be updated for older libraries, but this requires significant extra code, and #ifdefs. Those libraries are over three years old, and there concerns whether it makes sense to build modern software for real world use against such old libraries. Thusly, remove #ifdefs and code for old OpenSSL and LibreSSL support. Signed-off-by: Alexandru Gagniuc <[email protected]>
2021-07-28mkimage: use environment variable MKIMAGE_SIGN_PIN to set pin for OpenSSL EngineMarc Kleine-Budde
This patch adds the possibility to pass the PIN the OpenSSL Engine used during signing via the environment variable MKIMAGE_SIGN_PIN. This follows the approach used during kernel module signing ("KBUILD_SIGN_PIN") or UBIFS image signing ("MKIMAGE_SIGN_PIN"). Signed-off-by: Marc Kleine-Budde <[email protected]>
2021-07-28lib: rsa: rsa-sign: Minor bug in debug messageChan, Donald
*sig_size isn't set until later so use the correct variables. Signed-off-by: Donald Chan <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-07-28lib: rsa: rsa-verify: Fix a typo in a debug messageThomas Perrot
Signed-off-by: Thomas Perrot <[email protected]>