commit e01b09d5cecac33fa8633a18982560e34a67ee88 Author: Chelsea H. Komlo chelsea.komlo@gmail.com Date: Thu Nov 17 23:02:39 2016 -0500
crypto_digest512 returns expected error value of -1 --- src/common/crypto.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/common/crypto.c b/src/common/crypto.c index c075423..2571829 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1737,7 +1737,7 @@ crypto_digest256(char *digest, const char *m, size_t len,
/** Compute a 512-bit digest of <b>len</b> bytes in data stored in <b>m</b>, * using the algorithm <b>algorithm</b>. Write the DIGEST_LEN512-byte result - * into <b>digest</b>. Return 0 on success, 1 on failure. */ + * into <b>digest</b>. Return 0 on success, -1 on failure. */ int crypto_digest512(char *digest, const char *m, size_t len, digest_algorithm_t algorithm) @@ -1745,12 +1745,18 @@ crypto_digest512(char *digest, const char *m, size_t len, tor_assert(m); tor_assert(digest); tor_assert(algorithm == DIGEST_SHA512 || algorithm == DIGEST_SHA3_512); + + int ret = 0; if (algorithm == DIGEST_SHA512) - return (SHA512((const unsigned char*)m,len,(unsigned char*)digest) - == NULL); + ret = (SHA512((const unsigned char*)m,len,(unsigned char*)digest) + != NULL); else - return (sha3_512((uint8_t*)digest, DIGEST512_LEN, (const uint8_t*)m, len) - == -1); + ret = (sha3_512((uint8_t*)digest, DIGEST512_LEN, (const uint8_t*)m, len) + > -1); + + if (!ret) + return -1; + return 0; }
/** Set the common_digests_t in <b>ds_out</b> to contain every digest on the
tor-commits@lists.torproject.org