X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_pbkdf2.cpp;h=89bc39ef4cf8e40f13ef59b8d833e991fa949f0b;hb=9a312de26b742e9c399a84a70b175a88fb4bc1ac;hp=b66b3f05891fa972943ed8c2823cb4f2555212e7;hpb=4e0c477eb3333a7dab407f073313d21bb5027b02;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_pbkdf2.cpp b/src/modules/m_pbkdf2.cpp index b66b3f058..89bc39ef4 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; } @@ -145,8 +147,8 @@ class ModulePBKDF2 : public Module { // First set the common values ConfigTag* tag = ServerInstance->Config->ConfValue("pbkdf2"); - unsigned int global_iterations = tag->getInt("iterations", 12288, 1); - unsigned int global_dkey_length = tag->getInt("length", 32, 1, 1024); + unsigned int global_iterations = tag->getUInt("iterations", 12288, 1); + unsigned int global_dkey_length = tag->getUInt("length", 32, 1, 1024); for (std::vector::iterator i = providers.begin(); i != providers.end(); ++i) { PBKDF2Provider* pi = *i; @@ -166,8 +168,8 @@ class ModulePBKDF2 : public Module if (pi->provider->name != hash_name) continue; - pi->iterations = tag->getInt("iterations", global_iterations, 1); - pi->dkey_length = tag->getInt("length", global_dkey_length, 1, 1024); + pi->iterations = tag->getUInt("iterations", global_iterations, 1); + pi->dkey_length = tag->getUInt("length", global_dkey_length, 1, 1024); } } } @@ -178,71 +180,35 @@ class ModulePBKDF2 : public Module stdalgo::delete_all(providers); } - void Prioritize() CXX11_OVERRIDE + void OnServiceAdd(ServiceProvider& provider) CXX11_OVERRIDE { - OnLoadModule(NULL); - } - - void OnLoadModule(Module* mod) CXX11_OVERRIDE - { - bool newProv = false; - // As the module doesn't tell us what ServiceProviders it has, let's iterate all (yay ...) the ServiceProviders - // Good thing people don't run loading and unloading those all the time - for (std::multimap::iterator i = ServerInstance->Modules->DataProviders.begin(); i != ServerInstance->Modules->DataProviders.end(); ++i) - { - ServiceProvider* provider = i->second; - - // Does the service belong to the new mod? - // In the case this is our first run (mod == NULL, continue anyway) - if (mod && provider->creator != mod) - continue; - - // Check if it's a hash provider - if (provider->name.compare(0, 5, "hash/")) - continue; - - HashProvider* hp = static_cast(provider); - - if (hp->IsKDF()) - continue; - - bool has_prov = false; - for (std::vector::const_iterator j = providers.begin(); j != providers.end(); ++j) - { - if ((*j)->provider == hp) - { - has_prov = true; - break; - } - } - if (has_prov) - continue; + // Check if it's a hash provider + if (provider.name.compare(0, 5, "hash/")) + return; - newProv = true; + HashProvider* hp = static_cast(&provider); + if (hp->IsKDF()) + return; - PBKDF2Provider* prov = new PBKDF2Provider(this, hp); - providers.push_back(prov); - ServerInstance->Modules->AddService(*prov); - } + PBKDF2Provider* prov = new PBKDF2Provider(this, hp); + providers.push_back(prov); + ServerInstance->Modules.AddService(*prov); - if (newProv) - GetConfig(); + GetConfig(); } - void OnUnloadModule(Module* mod) CXX11_OVERRIDE + void OnServiceDel(ServiceProvider& prov) CXX11_OVERRIDE { - for (std::vector::iterator i = providers.begin(); i != providers.end(); ) + for (std::vector::iterator i = providers.begin(); i != providers.end(); ++i) { PBKDF2Provider* item = *i; - if (item->provider->creator != mod) - { - ++i; + if (item->provider != &prov) continue; - } ServerInstance->Modules->DelService(*item); delete item; - i = providers.erase(i); + providers.erase(i); + break; } }