diff options
author | Chelsea H. Komlo <chelsea.komlo@gmail.com> | 2016-11-17 23:02:39 -0500 |
---|---|---|
committer | Chelsea H. Komlo <chelsea.komlo@gmail.com> | 2016-11-24 12:14:54 -0500 |
commit | e01b09d5cecac33fa8633a18982560e34a67ee88 (patch) | |
tree | f7a252c7dd715c9edd8dbc1c13f626e822db4fe8 /src/common | |
parent | 9d9110f65db8af5ea4ddf93b01a099eb53e9b59f (diff) | |
download | tor-e01b09d5cecac33fa8633a18982560e34a67ee88.tar.gz tor-e01b09d5cecac33fa8633a18982560e34a67ee88.zip |
crypto_digest512 returns expected error value of -1
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index c075423d58..2571829b74 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 |