AnCH Framework  0.1
Another C++ Hack Framework
sha224_256.hpp
1 /*
2  ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3  Copyright (C) 2012 Vincent Lachenal
4 
5  This file is part of ANCH Framework.
6 
7  ANCH Framework is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  ANCH Framework is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef _ANCH_CRYPTO_SHA224_256_H_
21 #define _ANCH_CRYPTO_SHA224_256_H_
22 
23 #include "crypto/hash/sha2.hpp"
24 
25 #include <array>
26 #include <list>
27 
28 
29 namespace anch {
30  namespace crypto {
31 
32  template<typename H> H HMAC(const std::string&, const std::string&);
33 
43  template<std::size_t O, const std::array<uint32_t,8>& I>
44  class SHA224_256: public SHA2<O,64,uint32_t,64,I> {
45 
46  friend SHA224_256 anch::crypto::HMAC<SHA224_256>(const std::string&, const std::string&);
47 
48  // Constructors +
49  public:
53  SHA224_256(): SHA2<O,64,uint32_t,64,I>() {
54  // Nothing to do
55  }
56 
62  template<class CharT, class Traits, class Allocator>
63  SHA224_256(const std::basic_string<CharT,Traits,Allocator>& data):
64  SHA2<O,64,uint32_t,64,I>() {
65  Hash<O,64>::digest(data);
66  }
67 
73  template<class CharT, class Traits>
74  SHA224_256(std::basic_istream<CharT,Traits>& stream):
75  SHA2<O,64,uint32_t,64,I>() {
76  Hash<O,64>::digest(stream);
77  }
78 
79  private:
86  SHA224_256(const uint8_t* data, std::size_t len):
88  Hash<O,64>::digest(data, len);
89  }
90  // Constructors -
91 
92 
93  // Destructor +
94  public:
98  virtual ~SHA224_256() {
99  // Nothing to do
100  }
101  // Destructor -
102 
103  // Methods +
104  private:
110  virtual const std::array<uint32_t,64>& getTranslationArray() const {
111  static std::array<uint32_t,64> trArray = { {
112  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
113  0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
114  0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
115  0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
116  0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
117  0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
118  0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
119  0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
120  0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
121  0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
122  0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
123  0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
124  0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
125  } };
126  return trArray;
127  }
128 
134  virtual uint32_t SIGMA0(uint32_t word) const {
138  }
139 
145  virtual uint32_t SIGMA1(uint32_t word) const {
149  }
150 
156  virtual uint32_t sigma0(uint32_t word) const {
160  }
161 
167  virtual uint32_t sigma1(uint32_t word) const {
168  return (SHA2<O,64,uint32_t,64,I>::rotateRight(17, word)
171  }
172  // Methods -
173 
174  };
175 
176  }
177 }
178 
179 #endif // _ANCH_CRYPTO_SHA224_256_H_
virtual const std::array< uint8_t, O > & digest() const =0
H HMAC(const std::string &, const std::string &)
Definition: hmac.hpp:38
SHA2 abstract class.
Definition: sha2.hpp:51
SHA2 224/256 implementation.
Definition: sha224_256.hpp:44
SHA224_256(std::basic_istream< CharT, Traits > &stream)
Definition: sha224_256.hpp:74
AnCH framework base namespace.
Definition: base64.hpp:28
SHA224_256()
Definition: sha224_256.hpp:53
SHA224_256(const std::basic_string< CharT, Traits, Allocator > &data)
Definition: sha224_256.hpp:63
virtual ~SHA224_256()
Definition: sha224_256.hpp:98