From 4cdfe669de129ee2287d6fa7d4f9e170ca04ab2f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 11 May 2008 23:39:12 +0000 Subject: fixed some thread safety bugs --- src/cipher.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/cipher.cpp') diff --git a/src/cipher.cpp b/src/cipher.cpp index e98bc3b..6a572b9 100644 --- a/src/cipher.cpp +++ b/src/cipher.cpp @@ -78,8 +78,10 @@ AesIcmCipher::AesIcmCipher() : cipher_(NULL) { // TODO: hardcoded keysize gcry_error_t err = gcry_cipher_open( &cipher_, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0 ); - if( err ) - cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher"; + if( err ) { + char buf[NL_TEXTMAX]; + cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher" << gpg_strerror_r(err, buf, NL_TEXTMAX); + } } @@ -95,8 +97,10 @@ void AesIcmCipher::setKey(Buffer& key) return; gcry_error_t err = gcry_cipher_setkey( cipher_, key.getBuf(), key.getLength() ); - if( err ) - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher::setKey: Failed to set cipher key: " << gpg_strerror( err ); + if( err ) { + char buf[NL_TEXTMAX]; + cLog.msg(Log::PRIO_ERR) << "AesIcmCipher::setKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, NL_TEXTMAX); + } } void AesIcmCipher::setSalt(Buffer& salt) @@ -125,7 +129,8 @@ void AesIcmCipher::calc(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t o gcry_error_t err = gcry_cipher_reset( cipher_ ); if( err ) { - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to reset cipher: " << gpg_strerror( err ); + char buf[NL_TEXTMAX]; + cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to reset cipher: " << gpg_strerror_r(err, buf, NL_TEXTMAX); return; } @@ -154,13 +159,15 @@ void AesIcmCipher::calc(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t o err = gcry_cipher_setctr( cipher_, ctr_buf, written ); // TODO: hardcoded size delete[] ctr_buf; if( err ) { - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << gpg_strerror( err ); + char buf[NL_TEXTMAX]; + cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << gpg_strerror_r(err, buf, NL_TEXTMAX); return; } err = gcry_cipher_encrypt( cipher_, out, olen, in, ilen ); if( err ) { - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to generate cipher bitstream: " << gpg_strerror( err ); + char buf[NL_TEXTMAX]; + cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to generate cipher bitstream: " << gpg_strerror_r(err, buf, NL_TEXTMAX); return; } } -- cgit v1.2.3