summaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorChelsea H. Komlo <chelsea.komlo@gmail.com>2016-11-17 22:58:36 -0500
committerChelsea H. Komlo <chelsea.komlo@gmail.com>2016-11-24 12:13:07 -0500
commit9d9110f65db8af5ea4ddf93b01a099eb53e9b59f (patch)
tree04edf37906e4e621dfcd6eb69a2d7d786a9b3c15 /src/common/crypto.c
parent276d07a88a3b595aff9e28c7f1862563d2751b55 (diff)
downloadtor-9d9110f65db8af5ea4ddf93b01a099eb53e9b59f.tar.gz
tor-9d9110f65db8af5ea4ddf93b01a099eb53e9b59f.zip
crypto_digest256 returns expected error value of -1
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index f59b6745ba..c075423d58 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1714,7 +1714,7 @@ crypto_digest(char *digest, const char *m, size_t len)
/** Compute a 256-bit digest of <b>len</b> bytes in data stored in <b>m</b>,
* using the algorithm <b>algorithm</b>. Write the DIGEST_LEN256-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_digest256(char *digest, const char *m, size_t len,
digest_algorithm_t algorithm)
@@ -1722,11 +1722,17 @@ crypto_digest256(char *digest, const char *m, size_t len,
tor_assert(m);
tor_assert(digest);
tor_assert(algorithm == DIGEST_SHA256 || algorithm == DIGEST_SHA3_256);
+
+ int ret = 0;
if (algorithm == DIGEST_SHA256)
- return (SHA256((const uint8_t*)m,len,(uint8_t*)digest) == NULL);
+ ret = (SHA256((const uint8_t*)m,len,(uint8_t*)digest) != NULL);
else
- return (sha3_256((uint8_t *)digest, DIGEST256_LEN,(const uint8_t *)m, len)
- == -1);
+ ret = (sha3_256((uint8_t *)digest, DIGEST256_LEN,(const uint8_t *)m, len)
+ > -1);
+
+ if (!ret)
+ return -1;
+ return 0;
}
/** Compute a 512-bit digest of <b>len</b> bytes in data stored in <b>m</b>,