From d6f586d0eaa9344a99248cc4dfb7825972f2a174 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 13 Feb 2006 19:52:43 +0000 Subject: * Optional switch "--with-openssl=" to use OpenSSL's implementations of MD5, SHA-1 and SHA-256. The main benefit is that we get assembler-optimised implementations of MD5 and SHA-1 (though not SHA-256 (at least on x86), unfortunately). OpenSSL's SHA-1 implementation on Intel is twice as fast as ours. --- src/libutil/hash.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/libutil/hash.cc') diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 6df75e956..04e9d2248 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -1,10 +1,17 @@ +#include "config.h" + #include +#ifdef HAVE_OPENSSL +#include +#include +#else extern "C" { #include "md5.h" #include "sha1.h" #include "sha256.h" } +#endif #include "hash.hh" #include "archive.hh" @@ -199,16 +206,16 @@ bool isHash(const string & s) union Ctx { - md5_ctx md5; - sha_ctx sha1; + MD5_CTX md5; + SHA_CTX sha1; SHA256_CTX sha256; }; static void start(HashType ht, Ctx & ctx) { - if (ht == htMD5) md5_init_ctx(&ctx.md5); - else if (ht == htSHA1) sha_init(&ctx.sha1); + if (ht == htMD5) MD5_Init(&ctx.md5); + else if (ht == htSHA1) SHA1_Init(&ctx.sha1); else if (ht == htSHA256) SHA256_Init(&ctx.sha256); } @@ -216,19 +223,16 @@ static void start(HashType ht, Ctx & ctx) static void update(HashType ht, Ctx & ctx, const unsigned char * bytes, unsigned int len) { - if (ht == htMD5) md5_process_bytes(bytes, len, &ctx.md5); - else if (ht == htSHA1) sha_update(&ctx.sha1, bytes, len); + if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len); + else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len); else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len); } static void finish(HashType ht, Ctx & ctx, unsigned char * hash) { - if (ht == htMD5) md5_finish_ctx(&ctx.md5, hash); - else if (ht == htSHA1) { - sha_final(&ctx.sha1); - sha_digest(&ctx.sha1, hash); - } + if (ht == htMD5) MD5_Final(hash, &ctx.md5); + else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1); else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256); } -- cgit v1.2.3