2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2012-01-01 00:32:13 +01:00
|
|
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
2010-10-07 15:35:36 +02:00
|
|
|
* Copyright (C) 2005-2009 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/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-07 07:43:20 -06:00
|
|
|
#include "HMACSHA1.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "BigNumber.h"
|
2012-01-24 00:24:39 +01:00
|
|
|
#include "Common.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
HmacHash::HmacHash(uint32 len, uint8 *seed)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
HMAC_CTX_init(&m_ctx);
|
2010-04-11 11:11:32 +04:00
|
|
|
HMAC_Init_ex(&m_ctx, seed, len, EVP_sha1(), NULL);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
HmacHash::~HmacHash()
|
|
|
|
|
{
|
|
|
|
|
HMAC_CTX_cleanup(&m_ctx);
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-09-15 14:08:17 +02:00
|
|
|
void HmacHash::UpdateBigNumber(BigNumber* bn)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
UpdateData(bn->AsByteArray(), bn->GetNumBytes());
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void HmacHash::UpdateData(const uint8 *data, int length)
|
|
|
|
|
{
|
|
|
|
|
HMAC_Update(&m_ctx, data, length);
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-11 20:20:38 +02:00
|
|
|
void HmacHash::UpdateData(const std::string &str)
|
|
|
|
|
{
|
|
|
|
|
UpdateData((uint8 const*)str.c_str(), str.length());
|
2010-04-11 11:11:32 +04:00
|
|
|
}
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void HmacHash::Finalize()
|
|
|
|
|
{
|
|
|
|
|
uint32 length = 0;
|
2009-06-11 00:45:59 -05:00
|
|
|
HMAC_Final(&m_ctx, (uint8*)m_digest, &length);
|
2008-10-02 16:23:55 -05:00
|
|
|
ASSERT(length == SHA_DIGEST_LENGTH)
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-09-15 14:08:17 +02:00
|
|
|
uint8 *HmacHash::ComputeHash(BigNumber* bn)
|
2009-06-11 00:45:59 -05:00
|
|
|
{
|
|
|
|
|
HMAC_Update(&m_ctx, bn->AsByteArray(), bn->GetNumBytes());
|
|
|
|
|
Finalize();
|
|
|
|
|
return (uint8*)m_digest;
|
|
|
|
|
}
|