summaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-08-20 01:47:13 -0400
committerNick Mathewson <nickm@torproject.org>2009-08-20 01:47:13 -0400
commitd0c212995a29644e0357c81abbc0e7ea652d2504 (patch)
tree56a54987b3b550e316a6035b24c34320723c309b /src/common/crypto.c
parentf57883a39e09e16f495a6b8706ca0d3b3a8df2a4 (diff)
downloadtor-d0c212995a29644e0357c81abbc0e7ea652d2504.tar.gz
tor-d0c212995a29644e0357c81abbc0e7ea652d2504.zip
Add a SHA256 implementation for platforms that lack it.
(This would be everywhere running OpenSSL 0.9.7x and earlier, including all current Macintosh users.) The code is based on Tom St Denis's LibTomCrypt implementation, modified to be way less general and use Tor's existing facilities. I picked this one because it was pretty fast and pretty free, and because Python uses it too.
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 51d4059f3e..dc645b5eda 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -62,6 +62,28 @@
#include <openssl/engine.h>
+#if OPENSSL_VERSION_NUMBER < 0x00908000l
+/* On OpenSSL versions before 0.9.8, there is no working SHA256
+ * implementation, so we use Tom St Denis's nice speedy one, slightly adapted
+ * to our needs */
+#define SHA256_CTX sha256_state
+#define SHA256_Init sha256_init
+#define SHA256_Update sha256_process
+#define LTC_ARGCHK(x) tor_assert(x)
+#include "sha256.c"
+#define SHA256_Final(a,b) sha256_done(b,a)
+
+static unsigned char *
+SHA256(const unsigned char *m, size_t len, unsigned char *d)
+{
+ SHA256_CTX ctx;
+ SHA256_Init(&ctx);
+ SHA256_Update(&ctx, m, len);
+ SHA256_Final(d, &ctx);
+ return d;
+}
+#endif
+
/** Macro: is k a valid RSA public or private key? */
#define PUBLIC_KEY_OK(k) ((k) && (k)->key && (k)->key->n)
/** Macro: is k a valid RSA private key? */