From 309467c64e007ea6841c07fdee35eaff0146d541 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 14:43:35 -0400 Subject: Rename tor_mem_is_zero to fast_mem_is_zero() For memeq and friends, "tor_" indicates constant-time and "fast_" indicates optimized. I'm fine with leaving the constant-time "safe_mem_is_zero" with its current name, but the "tor_" prefix on the current optimized version is misleading. Also, make the tor_digest*_is_zero() uniformly constant-time, and add a fast_digest*_is_zero() version to use as needed. A later commit in this branch will fix all the users of tor_mem_is_zero(). Closes ticket 30309. --- src/lib/string/util_string.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/lib/string/util_string.c') diff --git a/src/lib/string/util_string.c b/src/lib/string/util_string.c index 0c4e399008..f5061a11d2 100644 --- a/src/lib/string/util_string.c +++ b/src/lib/string/util_string.c @@ -71,7 +71,7 @@ tor_memstr(const void *haystack, size_t hlen, const char *needle) /** Return true iff the 'len' bytes at 'mem' are all zero. */ int -tor_mem_is_zero(const char *mem, size_t len) +fast_mem_is_zero(const char *mem, size_t len) { static const char ZERO[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, @@ -95,17 +95,14 @@ tor_mem_is_zero(const char *mem, size_t len) int tor_digest_is_zero(const char *digest) { - static const uint8_t ZERO_DIGEST[] = { - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 - }; - return tor_memeq(digest, ZERO_DIGEST, DIGEST_LEN); + return safe_mem_is_zero(digest, DIGEST_LEN); } /** Return true iff the DIGEST256_LEN bytes in digest are all zero. */ int tor_digest256_is_zero(const char *digest) { - return tor_mem_is_zero(digest, DIGEST256_LEN); + return safe_mem_is_zero(digest, DIGEST256_LEN); } /** Remove from the string s every character which appears in -- cgit v1.2.3-54-g00ecf