diff options
author | Erwin Nindl <nine@wirdorange.org> | 2007-12-12 16:55:28 +0000 |
---|---|---|
committer | Erwin Nindl <nine@wirdorange.org> | 2007-12-12 16:55:28 +0000 |
commit | f8eac2fafb58f58c6186afb7b4a2e6cebb16ffcc (patch) | |
tree | d35117c70b2daffe47c64ac43cbaccec3acda6db /authAlgo.cpp | |
parent | build error fixed (diff) |
codechanges in sha1authalgo
Diffstat (limited to 'authAlgo.cpp')
-rw-r--r-- | authAlgo.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/authAlgo.cpp b/authAlgo.cpp index 328a42f..cc345ca 100644 --- a/authAlgo.cpp +++ b/authAlgo.cpp @@ -31,6 +31,7 @@ #include "authAlgo.h" #include "log.h" #include "buffer.h" +#include "threadUtils.hpp" #include <gcrypt.h> @@ -45,6 +46,7 @@ const char* Sha1AuthAlgo::MIN_GCRYPT_VERSION = "1.2.3"; // HMAC_SHA1 Sha1AuthAlgo::Sha1AuthAlgo() : ctx_(NULL) { + Lock lock(mutex_); gcry_error_t err; // No other library has already initialized libgcrypt. if( !gcry_control(GCRYCTL_ANY_INITIALIZATION_P) ) @@ -69,12 +71,14 @@ Sha1AuthAlgo::Sha1AuthAlgo() : ctx_(NULL) Sha1AuthAlgo::~Sha1AuthAlgo() { + Lock lock(mutex_); gcry_md_close( ctx_ ); cLog.msg(Log::PRIO_DEBUG) << "Sha1AuthAlgo::~Sha1AuthAlgo: closed hmac handler"; } void Sha1AuthAlgo::setKey(Buffer key) { + Lock lock(mutex_); gcry_error_t err; err = gcry_md_setkey( ctx_, key.getBuf(), key.getLength() ); if( err ) @@ -84,12 +88,16 @@ void Sha1AuthAlgo::setKey(Buffer key) AuthTag Sha1AuthAlgo::calc(const Buffer& buf) { + Lock lock(mutex_); // gcry_error_t err; - Buffer hmac; //80bit + Buffer hmac(10); // 10byte + gcry_mpi_t tmp = gcry_mpi_new(160); // 20byte gcry_md_write( ctx_, static_cast<Buffer>(buf).getBuf(), buf.getLength() ); gcry_md_final( ctx_ ); - hmac = Buffer(gcry_md_read( ctx_, 0 ), 10); + gcry_mpi_scan( &tmp, GCRYMPI_FMT_STD, gcry_md_read(ctx_, 0), 20, NULL ); + gcry_mpi_clear_highbit( tmp, 81 ); // truncate hmac from 20byte to 10byte + gcry_mpi_print( GCRYMPI_FMT_STD, hmac, hmac.getLength(), NULL, tmp ); return hmac; } |