Wolframe, 0.0.3

CRAM.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 //
40 //
41 
42 #ifndef _CRAM_HPP_INCLUDED
43 #define _CRAM_HPP_INCLUDED
44 
45 #include <string>
47 #include <AAAA/passwordHash.hpp>
48 
49 namespace _Wolframe {
50 namespace AAAA {
51 
52 static const size_t CRAM_BLOCK_SIZE = 512 / 8;
53 static const size_t CRAM_DIGEST_SIZE = 256 / 8;
54 static const size_t CRAM_CHALLENGE_SIZE = CRAM_BLOCK_SIZE;
55 static const size_t CRAM_RESPONSE_SIZE = CRAM_DIGEST_SIZE;
56 static const size_t CRAM_SALT_SIZE = PASSWORD_SALT_SIZE;
57 
60 {
61 public:
62  CRAMchallenge( const crypto::RandomGenerator& rndGen );
63 
65 
66  const unsigned char* challenge() const { return m_challenge; }
67  std::size_t size() const { return CRAM_CHALLENGE_SIZE; }
68 
69  std::string toBCD() const;
70  std::string toString() const;
71 
73  std::string toString( const PasswordHash::Salt& salt ) const;
74 
75  std::string toString( const PasswordHash& password ) const {
76  return toString( password.salt() );
77  }
78 private:
79  unsigned char m_challenge[ CRAM_CHALLENGE_SIZE ];
80 };
81 
82 
85 {
86 public:
88  CRAMresponse( const CRAMchallenge& challenge, const PasswordHash& pwdHash );
89 
93  CRAMresponse( const std::string& challenge, const std::string& password );
94 
95  ~CRAMresponse();
96 
97  const unsigned char* response() const { return m_response; }
98  std::size_t size() const { return CRAM_RESPONSE_SIZE; }
99 
100  std::string toBCD() const;
101  std::string toString() const;
102 
104  bool operator == ( const CRAMresponse& rhs );
105  bool operator != ( const CRAMresponse& rhs ) { return !( *this == rhs ); }
106 
110  bool operator == ( const std::string& rhs );
111  bool operator != ( const std::string& rhs ) { return !( *this == rhs ); }
112 private:
113  unsigned char m_response[ CRAM_RESPONSE_SIZE ];
114 };
115 
117 class CRAMsalt
118 {
119 public:
122  CRAMsalt( const std::string& challenge );
123 
124  ~CRAMsalt();
125 
126  const unsigned char* salt() const { return m_salt; }
127  std::size_t size() const { return CRAM_SALT_SIZE; }
128 
129  std::string toBCD() const;
130  std::string toString() const;
131 
132 private:
133  unsigned char m_salt[ CRAM_SALT_SIZE ];
134 };
135 
136 }} // namespace _Wolframe::AAAA
137 
138 #endif // _CRAM_HPP_INCLUDED
139 
const unsigned char * response() const
Definition: CRAM.hpp:97
static const size_t CRAM_SALT_SIZE
Definition: CRAM.hpp:56
unsigned char m_response[CRAM_RESPONSE_SIZE]
Definition: CRAM.hpp:113
static const size_t CRAM_CHALLENGE_SIZE
Definition: CRAM.hpp:54
Random Generator interface class.
Definition: randomGenerator.hpp:45
std::string toString() const
Challenge for the authentication mech "Wolframe-CRAM".
Definition: CRAM.hpp:59
const unsigned char * challenge() const
Definition: CRAM.hpp:66
const Salt & salt() const
The password salt.
Definition: passwordHash.hpp:151
CRAMsalt(const std::string &challenge)
CRAMchallenge(const crypto::RandomGenerator &rndGen)
Definition: passwordHash.hpp:53
unsigned char m_salt[CRAM_SALT_SIZE]
Definition: CRAM.hpp:133
static const size_t CRAM_RESPONSE_SIZE
Definition: CRAM.hpp:55
std::string toBCD() const
Response for the authentication mech "Wolframe-CRAM".
Definition: CRAM.hpp:84
Random Generator interface class.
std::string toString() const
std::string toString() const
bool operator==(const CRAMresponse &rhs)
True if the 2 CRAM responses are identical, false otherwise.
Password hash.
Definition: passwordHash.hpp:50
std::size_t size() const
Definition: CRAM.hpp:98
std::size_t size() const
Definition: CRAM.hpp:67
static const size_t CRAM_BLOCK_SIZE
Definition: CRAM.hpp:52
Extract the password seed from the challenge message.
Definition: CRAM.hpp:117
bool operator!=(const CRAMresponse &rhs)
Definition: CRAM.hpp:105
std::size_t size() const
Definition: CRAM.hpp:127
static const size_t PASSWORD_SALT_SIZE
Definition: passwordHash.hpp:47
CRAMresponse(const CRAMchallenge &challenge, const PasswordHash &pwdHash)
Constructors.
std::string toBCD() const
const unsigned char * salt() const
Definition: CRAM.hpp:126
Wolframe password hashes.
std::string toBCD() const
unsigned char m_challenge[CRAM_CHALLENGE_SIZE]
Definition: CRAM.hpp:79
std::string toString(const PasswordHash &password) const
Definition: CRAM.hpp:75
static const size_t CRAM_DIGEST_SIZE
Definition: CRAM.hpp:53