Wolframe, 0.0.3

HMAC.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
36 
37 #ifndef _HMAC_HPP_INCLUDED
38 #define _HMAC_HPP_INCLUDED
39 
40 #include <string>
41 #include "HMAC.h"
42 
43 namespace _Wolframe {
44 namespace crypto {
45 
47 class HMAC_SHA1
48 {
49 public:
50  HMAC_SHA1( const unsigned char* key, size_t keySize,
51  const unsigned char* msg, size_t msgSize )
52  { hmac_sha1( key, keySize,
53  msg, msgSize, m_HMAC ); }
54  HMAC_SHA1( const std::string& key, const std::string& message )
55  { hmac_sha1( (const unsigned char*)key.data(), key.size(),
56  (const unsigned char*)message.data(), message.size(),
57  m_HMAC ); }
58  HMAC_SHA1( const unsigned char* key, size_t keySize, const std::string& message )
59  { hmac_sha1( key, keySize,
60  (const unsigned char*)message.data(), message.size(),
61  m_HMAC ); }
62  HMAC_SHA1( const std::string& key, const unsigned char* msg, size_t msgSize )
63  { hmac_sha1( (const unsigned char*)key.data(), key.size(),
64  msg, msgSize, m_HMAC ); }
65 
67  HMAC_SHA1( const std::string& str );
68 
69  const unsigned char* hash() const { return m_HMAC; }
70  std::size_t size() const { return HMAC_SHA1_HASH_SIZE; }
71 
73  bool operator == ( const HMAC_SHA1& rhs ) const;
74  bool operator != ( const HMAC_SHA1& rhs ) const { return !( *this == rhs ); }
75 
78  bool operator == ( const std::string& rhs ) const;
79  bool operator != ( const std::string& rhs ) const { return !( *this == rhs ); }
80 
82  std::string toBCD() const;
85  std::string toString() const;
86 private:
87  unsigned char m_HMAC[ HMAC_SHA1_HASH_SIZE ];
88 };
89 
90 
93 {
94 public:
95  HMAC_SHA256( const unsigned char* key, size_t keySize,
96  const unsigned char* msg, size_t msgSize )
97  { hmac_sha256( key, keySize,
98  msg, msgSize, m_HMAC ); }
99  HMAC_SHA256( const std::string& key, const std::string& message )
100  { hmac_sha256( (const unsigned char*)key.data(), key.size(),
101  (const unsigned char*)message.data(), message.size(),
102  m_HMAC ); }
103  HMAC_SHA256( const unsigned char* key, size_t keySize, const std::string& message )
104  { hmac_sha256( key, keySize,
105  (const unsigned char*)message.data(), message.size(),
106  m_HMAC ); }
107  HMAC_SHA256( const std::string& key, const unsigned char* msg, size_t msgSize )
108  { hmac_sha256( (const unsigned char*)key.data(), key.size(),
109  msg, msgSize, m_HMAC ); }
110 
112  HMAC_SHA256( const std::string& str );
113 
114  const unsigned char* hash() const { return m_HMAC; }
115  std::size_t size() const { return HMAC_SHA256_HASH_SIZE; }
116 
118  bool operator == ( const HMAC_SHA256& rhs ) const;
119  bool operator != ( const HMAC_SHA256& rhs ) const { return !( *this == rhs ); }
120 
123  bool operator == ( const std::string& rhs ) const;
124  bool operator != ( const std::string& rhs ) const { return !( *this == rhs ); }
125 
127  std::string toBCD() const;
130  std::string toString() const;
131 private:
132  unsigned char m_HMAC[ HMAC_SHA256_HASH_SIZE ];
133 };
134 
135 }} // namespace _Wolframe::crypto
136 
137 #endif // _HMAC_HPP_INCLUDED
HMAC_SHA256(const std::string &key, const std::string &message)
Definition: HMAC.hpp:99
HMAC_SHA256(const std::string &key, const unsigned char *msg, size_t msgSize)
Definition: HMAC.hpp:107
unsigned char m_HMAC[HMAC_SHA256_HASH_SIZE]
Definition: HMAC.hpp:132
HMAC_SHA256(const unsigned char *key, size_t keySize, const std::string &message)
Definition: HMAC.hpp:103
std::string toString() const
const unsigned char * hash() const
Definition: HMAC.hpp:69
Standard HMAC-SHA1 object.
Definition: HMAC.hpp:47
bool operator!=(const HMAC_SHA256 &rhs) const
Definition: HMAC.hpp:119
Standard HMAC-SHA256 object.
Definition: HMAC.hpp:92
std::string toBCD() const
BCD string representation of the HMAC value.
std::size_t size() const
Definition: HMAC.hpp:70
bool operator==(const HMAC_SHA1 &rhs) const
Comparisson operators.
HMAC_SHA1(const unsigned char *key, size_t keySize, const unsigned char *msg, size_t msgSize)
Definition: HMAC.hpp:50
bool operator==(const HMAC_SHA256 &rhs) const
Comparisson operators.
HMAC_SHA256(const unsigned char *key, size_t keySize, const unsigned char *msg, size_t msgSize)
Definition: HMAC.hpp:95
std::string toBCD() const
BCD string representation of the HMAC value.
std::string toString() const
std::size_t size() const
Definition: HMAC.hpp:115
HMAC_SHA1(const std::string &key, const std::string &message)
Definition: HMAC.hpp:54
HMAC_SHA1(const unsigned char *key, size_t keySize, const std::string &message)
Definition: HMAC.hpp:58
HMAC_SHA1(const std::string &key, const unsigned char *msg, size_t msgSize)
Definition: HMAC.hpp:62
const unsigned char * hash() const
Definition: HMAC.hpp:114
unsigned char m_HMAC[HMAC_SHA1_HASH_SIZE]
Definition: HMAC.hpp:87
bool operator!=(const HMAC_SHA1 &rhs) const
Definition: HMAC.hpp:74