mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
crypto_digest256 returns expected error value of -1
This commit is contained in:
parent
276d07a88a
commit
9d9110f65d
@ -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>,
|
/** 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
|
* 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
|
int
|
||||||
crypto_digest256(char *digest, const char *m, size_t len,
|
crypto_digest256(char *digest, const char *m, size_t len,
|
||||||
digest_algorithm_t algorithm)
|
digest_algorithm_t algorithm)
|
||||||
@ -1722,11 +1722,17 @@ crypto_digest256(char *digest, const char *m, size_t len,
|
|||||||
tor_assert(m);
|
tor_assert(m);
|
||||||
tor_assert(digest);
|
tor_assert(digest);
|
||||||
tor_assert(algorithm == DIGEST_SHA256 || algorithm == DIGEST_SHA3_256);
|
tor_assert(algorithm == DIGEST_SHA256 || algorithm == DIGEST_SHA3_256);
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
if (algorithm == DIGEST_SHA256)
|
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
|
else
|
||||||
return (sha3_256((uint8_t *)digest, DIGEST256_LEN,(const uint8_t *)m, len)
|
ret = (sha3_256((uint8_t *)digest, DIGEST256_LEN,(const uint8_t *)m, len)
|
||||||
== -1);
|
> -1);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a 512-bit digest of <b>len</b> bytes in data stored in <b>m</b>,
|
/** Compute a 512-bit digest of <b>len</b> bytes in data stored in <b>m</b>,
|
||||||
|
@ -4541,7 +4541,7 @@ router_get_hash_impl(const char *s, size_t s_len, char *digest,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (crypto_digest256(digest, start, end-start, alg)) {
|
if (crypto_digest256(digest, start, end-start, alg) < 0) {
|
||||||
log_warn(LD_BUG,"couldn't compute digest");
|
log_warn(LD_BUG,"couldn't compute digest");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ verify_commit_and_reveal(const sr_commit_t *commit)
|
|||||||
/* Use the invariant length since the encoded reveal variable has an
|
/* Use the invariant length since the encoded reveal variable has an
|
||||||
* extra byte for the NUL terminated byte. */
|
* extra byte for the NUL terminated byte. */
|
||||||
if (crypto_digest256(received_hashed_reveal, commit->encoded_reveal,
|
if (crypto_digest256(received_hashed_reveal, commit->encoded_reveal,
|
||||||
SR_REVEAL_BASE64_LEN, commit->alg)) {
|
SR_REVEAL_BASE64_LEN, commit->alg) < 0) {
|
||||||
/* Unable to digest the reveal blob, this is unlikely. */
|
/* Unable to digest the reveal blob, this is unlikely. */
|
||||||
goto invalid;
|
goto invalid;
|
||||||
}
|
}
|
||||||
@ -932,7 +932,7 @@ sr_generate_our_commit(time_t timestamp, const authority_cert_t *my_rsa_cert)
|
|||||||
/* The invariant length is used here since the encoded reveal variable
|
/* The invariant length is used here since the encoded reveal variable
|
||||||
* has an extra byte added for the NULL terminated byte. */
|
* has an extra byte added for the NULL terminated byte. */
|
||||||
if (crypto_digest256(commit->hashed_reveal, commit->encoded_reveal,
|
if (crypto_digest256(commit->hashed_reveal, commit->encoded_reveal,
|
||||||
SR_REVEAL_BASE64_LEN, commit->alg)) {
|
SR_REVEAL_BASE64_LEN, commit->alg) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1012,7 +1012,7 @@ sr_compute_srv(void)
|
|||||||
SMARTLIST_FOREACH(chunks, char *, s, tor_free(s));
|
SMARTLIST_FOREACH(chunks, char *, s, tor_free(s));
|
||||||
smartlist_free(chunks);
|
smartlist_free(chunks);
|
||||||
if (crypto_digest256(hashed_reveals, reveals, strlen(reveals),
|
if (crypto_digest256(hashed_reveals, reveals, strlen(reveals),
|
||||||
SR_DIGEST_ALG)) {
|
SR_DIGEST_ALG) < 0) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
current_srv = generate_srv(hashed_reveals, reveal_num,
|
current_srv = generate_srv(hashed_reveals, reveal_num,
|
||||||
|
Loading…
Reference in New Issue
Block a user