diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-27 15:36:42 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-27 16:18:42 -0400 |
commit | e165c9c304800718daa589469349282110e00909 (patch) | |
tree | e76462a054c9a1f465b1e38f192dce45a4b33e9c /src/common/util.c | |
parent | 9e592d1decf1b16128a716220de68322b51d6315 (diff) | |
download | tor-e165c9c304800718daa589469349282110e00909.tar.gz tor-e165c9c304800718daa589469349282110e00909.zip |
Move various mem* functions to lib/string
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/src/common/util.c b/src/common/util.c index 09d3b2679c..64efbc81e1 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -240,54 +240,6 @@ hex_str(const char *from, size_t fromlen) return buf; } -/** Compare the value of the string <b>prefix</b> with the start of the - * <b>memlen</b>-byte memory chunk at <b>mem</b>. Return as for strcmp. - * - * [As fast_memcmp(mem, prefix, strlen(prefix)) but returns -1 if memlen is - * less than strlen(prefix).] - */ -int -fast_memcmpstart(const void *mem, size_t memlen, - const char *prefix) -{ - size_t plen = strlen(prefix); - if (memlen < plen) - return -1; - return fast_memcmp(mem, prefix, plen); -} - -/** Return true iff the 'len' bytes at 'mem' are all zero. */ -int -tor_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, - }; - while (len >= sizeof(ZERO)) { - /* It's safe to use fast_memcmp here, since the very worst thing an - * attacker could learn is how many initial bytes of a secret were zero */ - if (fast_memcmp(mem, ZERO, sizeof(ZERO))) - return 0; - len -= sizeof(ZERO); - mem += sizeof(ZERO); - } - /* Deal with leftover bytes. */ - if (len) - return fast_memeq(mem, ZERO, len); - - return 1; -} - -/** Return true iff the DIGEST_LEN bytes in digest are all zero. */ -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 true if <b>string</b> is a valid 'key=[value]' string. * "value" is optional, to indicate the empty string. Log at logging * <b>severity</b> if something ugly happens. */ @@ -436,13 +388,6 @@ string_is_valid_nonrfc_hostname(const char *string) return result; } -/** 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 a newly allocated string equal to <b>string</b>, except that every * character in <b>chars_to_escape</b> is preceded by a backslash. */ char * |