Wolframe, 0.0.3

passwordHash.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 ************************************************************************/
33 //
36 
37 #ifndef _PASSWORD_HPP_INCLUDED
38 #define _PASSWORD_HPP_INCLUDED
39 
40 #include <string>
42 
43 namespace _Wolframe {
44 namespace AAAA {
45 
46 static const size_t PASSWORD_HASH_SIZE = 384 / 8;
47 static const size_t PASSWORD_SALT_SIZE = 128 / 8;
48 
51 {
52 public:
53  class Salt
54  {
55  friend class PasswordHash;
56  public:
58  Salt();
60  Salt( const crypto::RandomGenerator& rndGen );
62  Salt( const unsigned char* data, size_t bytes );
64  Salt( const std::string& str );
65 
67  ~Salt();
68 
70  bool operator == ( const Salt& rhs );
71  bool operator != ( const Salt& rhs ) { return !( *this == rhs ); }
72 
74  size_t size() const { return m_size; }
76  const unsigned char* salt() const { return m_salt; }
77 
79  std::string toBCD() const;
81  std::string toString() const;
82  private:
83  std::size_t m_size;
84  unsigned char m_salt[ PASSWORD_SALT_SIZE ];
85  };
86 
87  class Hash
88  {
89  friend class PasswordHash;
90  public:
92  Hash();
94  Hash( const unsigned char* data, size_t bytes );
96  Hash( const std::string& str );
97 
99  ~Hash();
100 
102  bool operator == ( const Hash& rhs );
103  bool operator != ( const Hash& rhs ) { return !( *this == rhs ); }
104 
106  size_t size() const { return PASSWORD_HASH_SIZE; }
108  const unsigned char* hash() const { return m_hash; }
109 
111  std::string toBCD() const;
114  std::string toString() const;
115  private:
116  unsigned char m_hash[ PASSWORD_HASH_SIZE ];
117  };
118 
121 
125  PasswordHash( const crypto::RandomGenerator& rndGen, const std::string& password );
126 
131  PasswordHash( const unsigned char* pwdSalt, size_t bytes, const std::string& password );
132 
136  PasswordHash( const Salt& pwdSalt, const std::string& password );
137 
141  PasswordHash( const std::string& pwdSalt, const std::string& password );
142 
148  PasswordHash( const std::string& str );
149 
151  const Salt& salt() const { return m_salt; }
152 
154  const Hash& hash() const { return m_hash; }
155 
158  std::string toBCD() const;
161  std::string toString() const;
162 
163 private:
166 };
167 
168 }} // namespace _Wolframe::AAAA
169 
170 #endif // _PASSWORD_HPP_INCLUDED
171 
unsigned char m_hash[PASSWORD_HASH_SIZE]
Definition: passwordHash.hpp:116
~Hash()
Destruct the password hash (set all bits 0).
const unsigned char * hash() const
The unsigned char vector of the password hash.
Definition: passwordHash.hpp:108
bool operator!=(const Salt &rhs)
Definition: passwordHash.hpp:71
bool operator!=(const Hash &rhs)
Definition: passwordHash.hpp:103
std::string toBCD() const
Return the password hash as a BCD encoded string.
std::size_t m_size
Definition: passwordHash.hpp:83
Random Generator interface class.
Definition: randomGenerator.hpp:45
static const size_t PASSWORD_HASH_SIZE
Definition: passwordHash.hpp:46
const Salt & salt() const
The password salt.
Definition: passwordHash.hpp:151
std::string toBCD() const
size_t size() const
The size of the password hash in bytes.
Definition: passwordHash.hpp:106
~Salt()
Destructor (set all bits 0).
std::string toString() const
Return the salt as a base64 encoded string (without base64 padding).
bool operator==(const Hash &rhs)
True if the 2 password hashes are identical, false otherwise.
Definition: passwordHash.hpp:53
Definition: passwordHash.hpp:87
const Hash & hash() const
The unsigned char vector of the password hash.
Definition: passwordHash.hpp:154
Random Generator interface class.
Salt m_salt
Definition: passwordHash.hpp:165
Password hash.
Definition: passwordHash.hpp:50
std::string toString() const
bool operator==(const Salt &rhs)
True if the 2 password salts are identical, false otherwise.
std::string toBCD() const
Return the salt as a BCD encoded string.
Hash()
Construct an empty password hash (all bits 0).
PasswordHash()
Construct an empty password hash.
Definition: passwordHash.hpp:120
static const size_t PASSWORD_SALT_SIZE
Definition: passwordHash.hpp:47
size_t size() const
The size of the salt in bytes.
Definition: passwordHash.hpp:74
Salt()
Construct an empty salt (all bits 0).
Hash m_hash
Definition: passwordHash.hpp:164
const unsigned char * salt() const
The unsigned char vector of the salt.
Definition: passwordHash.hpp:76
unsigned char m_salt[PASSWORD_SALT_SIZE]
Definition: passwordHash.hpp:84