summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-08-04 13:45:04 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-08-04 13:45:04 +0200
commit895b193c665bd7e6c43bbdb4b2819c258da86e25 (patch)
treedb4a6b0652adadf8943c5fd4a1a384508320cbd3 /src
parent4e0c477eb3333a7dab407f073313d21bb5027b02 (diff)
m_pbkdf2 Less string copying
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_pbkdf2.cpp10
1 files 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;
}