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. Signed-off-by: Andrew Cooper <[email protected]> --- CC: Jan Beulich <[email protected]> CC: Roger Pau Monné <[email protected]> --- xen/arch/x86/cpu/microcode/amd.c | 2 +- xen/include/xen/sha2.h | 4 ++-- xen/lib/sha2-256.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index e7ae1e802353..adabe6e6e838 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 09c69195a97d..7a99c1259d6e 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/sha2-256.c b/xen/lib/sha2-256.c index d1b2c20b9812..ed585ac0d4c1 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; -- 2.39.5
