diff options
Diffstat (limited to 'lib/mesa/src/util/mesa-sha1.c')
-rw-r--r-- | lib/mesa/src/util/mesa-sha1.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/mesa/src/util/mesa-sha1.c b/lib/mesa/src/util/mesa-sha1.c index 410e82c71..701ba8a28 100644 --- a/lib/mesa/src/util/mesa-sha1.c +++ b/lib/mesa/src/util/mesa-sha1.c @@ -26,6 +26,7 @@ #include "sha1/sha1.h" #include "mesa-sha1.h" +#include <string.h> void _mesa_sha1_compute(const void *data, size_t size, unsigned char result[20]) @@ -64,3 +65,36 @@ _mesa_sha1_hex_to_sha1(unsigned char *buf, const char *hex) buf[i] = strtol(tmp, NULL, 16); } } + +static void +sha1_to_uint32(const uint8_t sha1[SHA1_DIGEST_LENGTH], + uint32_t out[SHA1_DIGEST_LENGTH32]) +{ + memset(out, 0, SHA1_DIGEST_LENGTH); + + for (unsigned i = 0; i < SHA1_DIGEST_LENGTH; i++) + out[i / 4] |= (uint32_t)sha1[i] << ((i % 4) * 8); +} + +void +_mesa_sha1_print(FILE *f, const uint8_t sha1[SHA1_DIGEST_LENGTH]) +{ + uint32_t u32[SHA1_DIGEST_LENGTH]; + sha1_to_uint32(sha1, u32); + + for (unsigned i = 0; i < SHA1_DIGEST_LENGTH32; i++) { + fprintf(f, "0x%08x", u32[i]); + if (i < SHA1_DIGEST_LENGTH32 - 1) + fprintf(f, ", "); + } +} + +bool +_mesa_printed_sha1_equal(const uint8_t sha1[SHA1_DIGEST_LENGTH], + const uint32_t printed_sha1[SHA1_DIGEST_LENGTH32]) +{ + uint32_t u32[SHA1_DIGEST_LENGTH32]; + sha1_to_uint32(sha1, u32); + + return memcmp(u32, printed_sha1, sizeof(u32)) == 0; +} |