[SLOF] [PATCH v2 2/6] tcgbios: Use assembly for 32 bit rotr in sha256

Stefan Berger stefanb at linux.vnet.ibm.com
Fri Jul 9 00:45:57 AEST 2021


From: Stefan Berger <stefanb at linux.ibm.com>

Use assembly for the 32 bit rotr in the sha256 implementation.

Signed-off-by: Stefan Berger <stefanb at linux.ibm.com>
---
 lib/libtpm/sha256.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/libtpm/sha256.c b/lib/libtpm/sha256.c
index fb67e19..292e54e 100644
--- a/lib/libtpm/sha256.c
+++ b/lib/libtpm/sha256.c
@@ -22,10 +22,16 @@ typedef struct _sha256_ctx {
 	uint32_t h[8];
 } sha256_ctx;
 
-static inline uint32_t rotr(uint32_t x, uint8_t n)
-{
-	return (x >> n) | (x << (32 - n));
-}
+#define rotr(VAL, N)				\
+({						\
+	uint32_t res;				\
+	__asm__ (				\
+		"rotrwi %0, %1, %2\n\t"		\
+		: "=r" (res)			\
+		: "r" (VAL), "i" (N)		\
+	);					\
+	res; 					\
+})
 
 static inline uint32_t Ch(uint32_t x, uint32_t y, uint32_t z)
 {
-- 
2.17.1



More information about the SLOF mailing list