aboutsummaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-06 16:39:48 +0300
committerNick Mathewson <nickm@torproject.org>2017-07-07 11:12:27 -0400
commitf35f52e8697407dde391ebc4f1be6ba76e1a1bb2 (patch)
treee7fa941147878ba1bb48866a2d3bce77c86279a4 /src/common/crypto.c
parent70d08f764d9912e66a2c6c0f3e4241f563d53ebd (diff)
downloadtor-f35f52e8697407dde391ebc4f1be6ba76e1a1bb2.tar.gz
tor-f35f52e8697407dde391ebc4f1be6ba76e1a1bb2.zip
Hide crypto_digest_t again and use an accessor for tests.
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 8b214a63b9..875b4eeb56 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1839,6 +1839,33 @@ crypto_digest_algorithm_get_length(digest_algorithm_t alg)
}
}
+/** Intermediate information about the digest of a stream of data. */
+struct crypto_digest_t {
+ digest_algorithm_t algorithm; /**< Which algorithm is in use? */
+ /** State for the digest we're using. Only one member of the
+ * union is usable, depending on the value of <b>algorithm</b>. Note also
+ * that space for other members might not even be allocated!
+ */
+ union {
+ SHA_CTX sha1; /**< state for SHA1 */
+ SHA256_CTX sha2; /**< state for SHA256 */
+ SHA512_CTX sha512; /**< state for SHA512 */
+ keccak_state sha3; /**< state for SHA3-[256,512] */
+ } d;
+};
+
+#ifdef TOR_UNIT_TESTS
+
+digest_algorithm_t
+crypto_digest_get_algorithm(crypto_digest_t *digest)
+{
+ tor_assert(digest);
+
+ return digest->algorithm;
+}
+
+#endif
+
/**
* Return the number of bytes we need to malloc in order to get a
* crypto_digest_t for <b>alg</b>, or the number of bytes we need to wipe