root/trunk/src/shared/Auth/Hmac.cpp @ 9

Revision 2, 1.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#include "Auth/Hmac.h"
20#include "BigNumber.h"
21
22HmacHash::HmacHash()
23{
24    uint8 temp[SEED_KEY_SIZE] = { 0x38, 0xA7, 0x83, 0x15, 0xF8, 0x92, 0x25, 0x30, 0x71, 0x98, 0x67, 0xB1, 0x8C, 0x4, 0xE2, 0xAA };
25    memcpy(&m_key, &temp, SEED_KEY_SIZE);
26    HMAC_CTX_init(&m_ctx);
27    HMAC_Init_ex(&m_ctx, &m_key, SEED_KEY_SIZE, EVP_sha1(), NULL);
28}
29
30HmacHash::~HmacHash()
31{
32    memset(&m_key, 0x00, SEED_KEY_SIZE);
33    HMAC_CTX_cleanup(&m_ctx);
34}
35
36void HmacHash::UpdateBigNumber(BigNumber *bn)
37{
38    UpdateData(bn->AsByteArray(), bn->GetNumBytes());
39}
40
41void HmacHash::UpdateData(const uint8 *data, int length)
42{
43    HMAC_Update(&m_ctx, data, length);
44}
45
46void HmacHash::Initialize()
47{
48    HMAC_Init_ex(&m_ctx, &m_key, SEED_KEY_SIZE, EVP_sha1(), NULL);
49}
50
51void HmacHash::Finalize()
52{
53    uint32 length = 0;
54    HMAC_Final(&m_ctx, m_digest, &length);
55    ASSERT(length == SHA_DIGEST_LENGTH)
56}
Note: See TracBrowser for help on using the browser.