|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] xen/lib: Misc SHA2 cleanup
commit 674409fc648c7b7e918d8c115095cebeddab512b
Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Fri Nov 28 15:09:08 2025 +0000
Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Tue Dec 2 17:11:52 2025 +0000
xen/lib: Misc SHA2 cleanup
In sha2_256_transform(), make state be an array of 8 rather than a pointer,
which lets the compiler do slightly more checking.
For better or worse, the canonical API in Linux is just the algorithm name.
As we're intending to import more from Linux in this area, drop the digest
suffix before we gain more users.
Compile sha2-256.o for all architectures. It's not very much code, and it
will be omitted at link time.
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
xen/arch/x86/cpu/microcode/amd.c | 2 +-
xen/include/xen/sha2.h | 4 ++--
xen/lib/Makefile | 2 +-
xen/lib/sha2-256.c | 8 ++++----
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c
index e7ae1e8023..adabe6e6e8 100644
--- a/xen/arch/x86/cpu/microcode/amd.c
+++ b/xen/arch/x86/cpu/microcode/amd.c
@@ -139,7 +139,7 @@ static bool check_digest(const struct container_microcode
*mc)
return false;
}
- sha2_256_digest(digest, patch, mc->len);
+ sha2_256(digest, patch, mc->len);
if ( memcmp(digest, pd->digest, sizeof(digest)) )
{
diff --git a/xen/include/xen/sha2.h b/xen/include/xen/sha2.h
index 09c69195a9..7a99c1259d 100644
--- a/xen/include/xen/sha2.h
+++ b/xen/include/xen/sha2.h
@@ -9,8 +9,8 @@
#define SHA2_256_DIGEST_SIZE 32
-void sha2_256_digest(uint8_t digest[SHA2_256_DIGEST_SIZE],
- const void *msg, size_t len);
+void sha2_256(uint8_t digest[SHA2_256_DIGEST_SIZE],
+ const void *msg, size_t len);
struct sha2_256_state {
uint32_t state[SHA2_256_DIGEST_SIZE / sizeof(uint32_t)];
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index 5ccb1e5241..d3e4f981b0 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -17,7 +17,7 @@ lib-y += memset.o
lib-y += muldiv64.o
lib-y += parse-size.o
lib-y += rbtree.o
-lib-$(CONFIG_X86) += sha2-256.o
+lib-y += sha2-256.o
lib-y += sort.o
lib-y += strcasecmp.o
lib-y += strchr.o
diff --git a/xen/lib/sha2-256.c b/xen/lib/sha2-256.c
index d1b2c20b98..ed585ac0d4 100644
--- a/xen/lib/sha2-256.c
+++ b/xen/lib/sha2-256.c
@@ -68,7 +68,7 @@ static const uint32_t K[] = {
0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U,
};
-static void sha2_256_transform(uint32_t *state, const void *_input)
+static void sha2_256_transform(uint32_t state[8], const void *_input)
{
const uint32_t *input = _input;
uint32_t a, b, c, d, e, f, g, h, t1, t2;
@@ -197,8 +197,8 @@ void sha2_256_final(struct sha2_256_state *s, uint8_t
digest[SHA2_256_DIGEST_SIZ
put_unaligned_be32(s->state[i], &dst[i]);
}
-void sha2_256_digest(uint8_t digest[SHA2_256_DIGEST_SIZE],
- const void *msg, size_t len)
+void sha2_256(uint8_t digest[SHA2_256_DIGEST_SIZE],
+ const void *msg, size_t len)
{
struct sha2_256_state s;
@@ -243,7 +243,7 @@ static void __init __constructor test_sha2_256(void)
const struct test *t = &tests[i];
uint8_t res[SHA2_256_DIGEST_SIZE] = {};
- sha2_256_digest(res, t->msg, strlen(t->msg));
+ sha2_256(res, t->msg, strlen(t->msg));
if ( memcmp(res, t->digest, sizeof(t->digest)) == 0 )
continue;
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |