diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-03-19 23:15:54 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-03-19 23:15:54 +0100 |
commit | 680c12a4bfc3dfb181ee8751365abf203fcbb56d (patch) | |
tree | f9003ed806ccdb739ae27ea22d80e28f704c7cb9 /src/common/Cryptography/SessionKeyGeneration.h | |
parent | 8f80b3e0ec05356a12056ef8a178f11a8d3dad48 (diff) |
Core/Crypto: Renamed SHA1Randx/WardenKeyGeneration and made it a template class
Diffstat (limited to 'src/common/Cryptography/SessionKeyGeneration.h')
-rw-r--r-- | src/common/Cryptography/SessionKeyGeneration.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/common/Cryptography/SessionKeyGeneration.h b/src/common/Cryptography/SessionKeyGeneration.h new file mode 100644 index 00000000000..0ec4479b765 --- /dev/null +++ b/src/common/Cryptography/SessionKeyGeneration.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SessionKeyGeneration_h__ +#define SessionKeyGeneration_h__ + +#include "Common.h" + +template<class Hash> +class SessionKeyGenerator +{ +public: + SessionKeyGenerator(uint8* buff, uint32 size) + { + uint32 halfSize = size / 2; + + sh.Initialize(); + sh.UpdateData(buff, halfSize); + sh.Finalize(); + + memcpy(o1, sh.GetDigest(), Hash::DigestLength::value); + + sh.Initialize(); + sh.UpdateData(buff + halfSize, size - halfSize); + sh.Finalize(); + + memcpy(o2, sh.GetDigest(), Hash::DigestLength::value); + + memset(o0, 0x00, Hash::DigestLength::value); + + FillUp(); + } + + void Generate(uint8* buf, uint32 sz) + { + for (uint32 i = 0; i < sz; ++i) + { + if (taken == Hash::DigestLength::value) + FillUp(); + + buf[i] = o0[taken]; + taken++; + } + } + +private: + void FillUp() + { + sh.Initialize(); + sh.UpdateData(o1, Hash::DigestLength::value); + sh.UpdateData(o0, Hash::DigestLength::value); + sh.UpdateData(o2, Hash::DigestLength::value); + sh.Finalize(); + + memcpy(o0, sh.GetDigest(), Hash::DigestLength::value); + + taken = 0; + } + + Hash sh; + uint32 taken; + uint8 o0[Hash::DigestLength::value]; + uint8 o1[Hash::DigestLength::value]; + uint8 o2[Hash::DigestLength::value]; +}; + +#endif // SessionKeyGeneration_h__ |