TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HmacHash.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _AUTH_HMAC_H
20 #define _AUTH_HMAC_H
21 
22 #include "Define.h"
23 #include <string>
24 #include <openssl/hmac.h>
25 #include <openssl/sha.h>
26 
27 class BigNumber;
28 
29 #define SEED_KEY_SIZE 16
30 
31 typedef EVP_MD const* (*HashCreateFn)();
32 
33 template<HashCreateFn HashCreator, uint32 DigestLength>
35 {
36  public:
37  HmacHash(uint32 len, uint8 const* seed);
38  ~HmacHash();
39  void UpdateData(std::string const& str);
40  void UpdateData(uint8 const* data, size_t len);
41  void Finalize();
42  uint8* ComputeHash(BigNumber* bn);
43  uint8* GetDigest() { return _digest; }
44  uint32 GetLength() const { return DigestLength; }
45  private:
46  HMAC_CTX _ctx;
47  uint8 _digest[DigestLength];
48 };
49 
52 
53 #endif
Definition: BigNumber.h:28
HmacHash< EVP_sha1, SHA_DIGEST_LENGTH > HmacSha1
Definition: HmacHash.h:50
HmacHash< EVP_sha256, SHA256_DIGEST_LENGTH > HmacSha256
Definition: HmacHash.h:51
HMAC_CTX _ctx
Definition: HmacHash.h:46
Definition: HmacHash.h:34
uint32 GetLength() const
Definition: HmacHash.h:44
Definition: UpdateData.h:59
uint8 * GetDigest()
Definition: HmacHash.h:43
uint32_t uint32
Definition: Define.h:150
#define TC_COMMON_API
Definition: Define.h:116
uint8_t uint8
Definition: Define.h:152