aboutsummaryrefslogtreecommitdiff
path: root/src/lib/string
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-05-07 08:02:39 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-05-07 08:02:39 -0400
commitb72f5da03d12e0ac2212d18e3dea309d23ded79c (patch)
tree82789d2222286e6b5500cb357448def627171df9 /src/lib/string
parentc8c64caf371c2960bf217fc10d2353144e7e24b3 (diff)
parent295feeb09377c4d78f9ee43ec3197b908d7cb960 (diff)
downloadtor-b72f5da03d12e0ac2212d18e3dea309d23ded79c.tar.gz
tor-b72f5da03d12e0ac2212d18e3dea309d23ded79c.zip
Merge branch 'tor-github/pr/994'
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/lib/string')
-rw-r--r--src/lib/string/util_string.c9
-rw-r--r--src/lib/string/util_string.h5
2 files changed, 7 insertions, 7 deletions
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 <b>s</b> every character which appears in
diff --git a/src/lib/string/util_string.h b/src/lib/string/util_string.h
index da4fab159c..b3c6841d41 100644
--- a/src/lib/string/util_string.h
+++ b/src/lib/string/util_string.h
@@ -20,7 +20,10 @@ const void *tor_memmem(const void *haystack, size_t hlen, const void *needle,
size_t nlen);
const void *tor_memstr(const void *haystack, size_t hlen,
const char *needle);
-int tor_mem_is_zero(const char *mem, size_t len);
+int fast_mem_is_zero(const char *mem, size_t len);
+#define fast_digest_is_zero(d) fast_mem_is_zero((d), DIGEST_LEN)
+#define fast_digetst256_is_zero(d) fast_mem_is_zero((d), DIGEST256_LEN)
+
int tor_digest_is_zero(const char *digest);
int tor_digest256_is_zero(const char *digest);