From 895b193c665bd7e6c43bbdb4b2819c258da86e25 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 4 Aug 2014 13:45:04 +0200 Subject: m_pbkdf2 Less string copying --- src/modules/m_pbkdf2.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/m_pbkdf2.cpp b/src/modules/m_pbkdf2.cpp index b66b3f058..314f6b836 100644 --- a/src/modules/m_pbkdf2.cpp +++ b/src/modules/m_pbkdf2.cpp @@ -81,24 +81,26 @@ class PBKDF2Provider : public HashProvider size_t blocks = std::ceil((double)dkl / provider->out_size); std::string output; + std::string tmphash; + std::string salt_block = salt; for (size_t block = 1; block <= blocks; block++) { char salt_data[4]; for (size_t i = 0; i < sizeof(salt_data); i++) salt_data[i] = block >> (24 - i * 8) & 0x0F; - std::string salt_block(salt_data, 4); - salt_block = salt + salt_block; + salt_block.erase(salt.length()); + salt_block.append(salt_data, sizeof(salt_data)); std::string blockdata = provider->hmac(pass, salt_block); std::string lasthash = blockdata; for (size_t iter = 1; iter < itr; iter++) { - std::string tmphash = provider->hmac(pass, lasthash); + tmphash = provider->hmac(pass, lasthash); for (size_t i = 0; i < provider->out_size; i++) blockdata[i] ^= tmphash[i]; - lasthash = tmphash; + lasthash.swap(tmphash); } output += blockdata; } -- cgit v1.2.3