X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fsha1.c;h=9ed26fd1ebe418d36eb3f9373d4baaf255cc0139;hp=bd83a413745bd0f8c8bd747517c09cad6c939a2d;hb=048e046524eef96a68f9c7b9cfee27919ec06a6c;hpb=095414a7528774641304f8dd1fefb14d466fe1c0 diff --git a/src/sha1.c b/src/sha1.c index bd83a413..9ed26fd1 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -23,6 +23,26 @@ * mean "SHA-1 not specified". */ const u8 zero_hash[20]; +/* + * Builds a hexadecimal string representation of a SHA-1 message digest. + * + * The output buffer must be at least 41 characters. + */ +void +sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_SIZE * 2 + 1]) +{ + int i; + u8 high, low; + + for (i = 0; i < SHA1_HASH_SIZE; i++) { + high = hash[i] >> 4; + low = hash[i] & 0xF; + strbuf[i * 2 + 0] = (high < 10 ? high + '0' : high - 10 + 'a'); + strbuf[i * 2 + 1] = (low < 10 ? low + '0' : low - 10 + 'a'); + } + strbuf[i * 2] = 0; +} + /* If we use libcrypto (e.g. OpenSSL) then we get all the SHA-1 functions for * free. Otherwise we need to implement them ourselves. */