MCPcopy Create free account
hub / github.com/coreutils/coreutils / hex_equal

Function hex_equal

src/cksum.c:1342–1363  ·  view source on GitHub ↗

Return true if HEX_DIGEST is the same as the hex-encoded digest of the DIGEST_LENGTH/8 bytes at BIN_BUFFER. */

Source from the content-addressed store, hash-verified

1340/* Return true if HEX_DIGEST is the same as the hex-encoded digest of the
1341 DIGEST_LENGTH/8 bytes at BIN_BUFFER. */
1342static bool
1343hex_equal (unsigned char const *hex_digest, unsigned char const *bin_buffer)
1344{
1345 static const char bin2hex[] = { '0', '1', '2', '3',
1346 '4', '5', '6', '7',
1347 '8', '9', 'a', 'b',
1348 'c', 'd', 'e', 'f' };
1349 idx_t digest_bin_bytes = digest_hex_bytes >> 1;
1350
1351 /* Compare generated binary number with text representation
1352 in check file. Ignore case of hex digits. */
1353 idx_t cnt;
1354 for (cnt = 0; cnt < digest_bin_bytes; ++cnt)
1355 {
1356 if (c_tolower (hex_digest[2 * cnt])
1357 != bin2hex[bin_buffer[cnt] >> 4]
1358 || (c_tolower (hex_digest[2 * cnt + 1])
1359 != (bin2hex[bin_buffer[cnt] & 0xf])))
1360 break;
1361 }
1362 return cnt == digest_bin_bytes;
1363}
1364
1365static bool
1366digest_check (char const *checkfile_name)

Callers 1

digest_checkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected