Skip to contentSkip to conversation

sample/tsm-mr: Use SHA-2 library APIs

PATCH In review Eric Biggers 3 participants 4 messages Mar 18 – Mar 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sample/tsm-mr: Use SHA-2 library APIs

Given that tsm_mr_sample has a particular set of algorithms that it wants, just use the library APIs for those algorithms rather than crypto_shash. This is more straightforward and a bit more efficient.

This fixes an issue where this module failed to build due to the kconfig options CRYPTO and CRYPTO_HASH not being selected. Also, even if it built, crypto_alloc_shash() could fail at runtime due to the needed algorithms not being available.

The library functions simply use direct linking. So if it builds, which it will due to the kconfig options being enabled, they are available.

Fixes f6953f1f9ec4 ("tsm-mr: Add tsm-mr sample code")
Fixes 44a3873df811 ("coco/guest: Remove unneeded selection of CRYPTO")

---

I'd like to take this via libcrypto-next, as that is where "coco/guest: Remove unneeded selection of CRYPTO" is.

This is an alternative to
https://lore.kernel.org/r/[email protected]

 samples/Kconfig                |  2 +
 samples/tsm-mr/tsm_mr_sample.c | 68 +++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 35 deletions(-)
samples/Kconfig +2 -0
index 5bc7c9e5a59e..a75e8e78330d 100644
@@ -184,10 +184,12 @@ config SAMPLE_TIMER
 	bool "Timer sample"
 	depends on CC_CAN_LINK && HEADERS_INSTALL
 
 config SAMPLE_TSM_MR
 	tristate "TSM measurement sample"
+	select CRYPTO_LIB_SHA256
+	select CRYPTO_LIB_SHA512
 	select TSM_MEASUREMENTS
 	select VIRT_DRIVERS
 	help
 	  Build a sample module that emulates MRs (Measurement Registers) and
 	  exposes them to user mode applications through the TSM sysfs
samples/tsm-mr/tsm_mr_sample.c +33 -35

95 lines not on this page · raw message

Signature · 1 line
2.53.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Eric Biggers

Given that tsm_mr_sample has a particular set of algorithms that it wants, just use the library APIs for those algorithms rather than crypto_shash. This is more straightforward and a bit more efficient.

This fixes an issue where this module failed to build due to the kconfig options CRYPTO and CRYPTO_HASH not being selected. Also, even if it built, crypto_alloc_shash() could fail at runtime due to the needed algorithms not being available.

The library functions simply use direct linking. So if it builds, which it will due to the kconfig options being enabled, they are available.

Quoted 7 lines
Fixes f6953f1f9ec4 ("tsm-mr: Add tsm-mr sample code")
Fixes 44a3873df811 ("coco/guest: Remove unneeded selection of CRYPTO")

---

I'd like to take this via libcrypto-next, as that is where "coco/guest: Remove unneeded selection of CRYPTO" is.

Thanks for fixing this! It is indeed nicer than the fix I sent earlier today.

#2 lore raw
Quoted 18 lines · Arnd Bergmann
Quoted 17 lines · Eric Biggers

Given that tsm_mr_sample has a particular set of algorithms that it wants, just use the library APIs for those algorithms rather than crypto_shash. This is more straightforward and a bit more efficient.

This fixes an issue where this module failed to build due to the kconfig options CRYPTO and CRYPTO_HASH not being selected. Also, even if it built, crypto_alloc_shash() could fail at runtime due to the needed algorithms not being available.

The library functions simply use direct linking. So if it builds, which it will due to the kconfig options being enabled, they are available.

Fixes f6953f1f9ec4 ("tsm-mr: Add tsm-mr sample code")
Fixes 44a3873df811 ("coco/guest: Remove unneeded selection of CRYPTO")

---

Quoted 7 lines
Quoted 2 lines

I'd like to take this via libcrypto-next, as that is where "coco/guest: Remove unneeded selection of CRYPTO" is.

Thanks for fixing this! It is indeed nicer than the fix I sent earlier today.

Thanks. Additional acks from the people owning this code (Dan, Cedric?) would be appreciated. But since this fixes a build error and is related to the crypto library, I went ahead and applied this to
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

I also found that the build error is pre-existing, as CRYPTO_HASH was not being selected. "coco/guest: Remove unneeded selection of CRYPTO" just made it a bit easier to encounter, by not selecting CRYPTO either.

So I updated the second paragraph of the commit message to:

This also fixes a bug where this module failed to build if it was enabled without CRYPTO_HASH happening to be set elsewhere in the kconfig. (With the concurrent change to make TSM_MEASUREMENTS stop selecting CRYPTO, this existing build error would have become easier to encounter, as well.) Also, even if it built, crypto_alloc_shash() could fail at runtime due to the needed algorithms not being available.

I also put this commit before "coco/guest: Remove unneeded selection of CRYPTO" and dropped the Fixes reference to that. So now it just has:

    Fixes: f6953f1f9ec4 ("tsm-mr: Add tsm-mr sample code")

- Eric

Acked-by
#3 lore raw
Quoted 45 lines · Eric Biggers
Quoted 18 lines · Arnd Bergmann
Quoted 17 lines · Eric Biggers

Given that tsm_mr_sample has a particular set of algorithms that it wants, just use the library APIs for those algorithms rather than crypto_shash. This is more straightforward and a bit more efficient.

This fixes an issue where this module failed to build due to the kconfig options CRYPTO and CRYPTO_HASH not being selected. Also, even if it built, crypto_alloc_shash() could fail at runtime due to the needed algorithms not being available.

The library functions simply use direct linking. So if it builds, which it will due to the kconfig options being enabled, they are available.

Fixes f6953f1f9ec4 ("tsm-mr: Add tsm-mr sample code")
Fixes 44a3873df811 ("coco/guest: Remove unneeded selection of CRYPTO")

---

Quoted 7 lines
Quoted 2 lines

I'd like to take this via libcrypto-next, as that is where "coco/guest: Remove unneeded selection of CRYPTO" is.

Thanks for fixing this! It is indeed nicer than the fix I sent earlier today.

Thanks. Additional acks from the people owning this code (Dan, Cedric?) would be appreciated. But since this fixes a build error and is related to the crypto library, I went ahead and applied this to
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

I also found that the build error is pre-existing, as CRYPTO_HASH was not being selected. "coco/guest: Remove unneeded selection of CRYPTO" just made it a bit easier to encounter, by not selecting CRYPTO either.

So I updated the second paragraph of the commit message to:

This also fixes a bug where this module failed to build if it was enabled without CRYPTO_HASH happening to be set elsewhere in the kconfig. (With the concurrent change to make TSM_MEASUREMENTS stop selecting CRYPTO, this existing build error would have become easier to encounter, as well.) Also, even if it built, crypto_alloc_shash() could fail at runtime due to the needed algorithms not being available.

Quoted 4 lines

I also put this commit before "coco/guest: Remove unneeded selection of CRYPTO" and dropped the Fixes reference to that. So now it just has:

    Fixes: f6953f1f9ec4 ("tsm-mr: Add tsm-mr sample code")

It looks good to me:

Feel free to take it through your tree since I have nothing immediately pending for tsm.git.