PALISADE Lattice Crypto Library  1.11.9
A lattice crypto library for software engineers by software engineers.
hashutil.h
1 // @file hashutil.h hash utilities.
2 // @author TPOC: contact@palisade-crypto.org
3 //
4 // @copyright Copyright (c) 2019, New Jersey Institute of Technology (NJIT)
5 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution. THIS SOFTWARE IS
13 // PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
14 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 // EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 #ifndef _SRC_LIB_UTILS_HASHUTIL_H
25 #define _SRC_LIB_UTILS_HASHUTIL_H
26 
27 #include <utils/exception.h>
28 #include <iostream>
29 #include <string>
30 #include <vector>
31 using std::string;
32 using std::vector;
33 
34 namespace lbcrypto {
35 
36 enum HashAlgorithm { SHA_256 = 0, SHA_512 = 1 };
37 
38 class HashUtil {
39  public:
40  static void Hash(string message, HashAlgorithm algo,
41  vector<int64_t>& digest) {
42  switch (algo) {
43  case SHA_256:
44  SHA256(message, digest);
45  return;
46 
47  case SHA_512:
48  // TODO SHA512 disabled, returning SHA256 instead
49  SHA256(message, digest);
50  return;
51 
52  default:
53  PALISADE_THROW(not_available_error, "ERROR: Unknown Hash Algorithm");
54  }
55  }
56 
57  static std::string HashString(std::string message);
58 
59  private:
60  static void SHA256(string message, vector<int64_t>& digest);
61  static void SHA512(string message, vector<int64_t>& digest);
62  static const uint32_t k_256[64];
63  static const uint64_t k_512[80];
64 };
65 
66 } // namespace lbcrypto
67 
68 #endif
Definition: hashutil.h:38
Definition: binfhecontext.h:36
Definition: exception.h:126