Sha2.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #ifndef ICL_CORE_CRYPT_SHA2_H_INCLUDED
24 #define ICL_CORE_CRYPT_SHA2_H_INCLUDED
25 
26 #include <icl_core/BaseTypes.h>
27 
29 
30 namespace icl_core {
32 namespace crypt {
33 
65 template <typename T, T t_h0, T t_h1, T t_h2, T t_h3, T t_h4, T t_h5, T t_h6, T t_h7, size_t t_len>
66 class Sha2 : public Sha2Impl<T, t_h0, t_h1, t_h2, t_h3, t_h4, t_h5, t_h6, t_h7, t_len>
67 {
68 public:
72  using Impl::clear;
73  using Impl::getHexDigest;
74 
76  Sha2();
77 
79  Sha2& process(const char *data);
82  { return process(data.c_str(), data.size()); }
84  Sha2& process(const void *data, size_t size);
85 
87  Sha2& finalize();
88 
89 protected:
93  void finalizeBuffer(size_t size);
94 
95  using Impl::processBuffer;
96  using Impl::m_digest;
98  using Impl::m_buffer;
99  using Impl::m_buffer_fill;
100 };
101 
102 }
103 }
104 
105 #include "icl_core_crypt/Sha2.hpp"
106 
107 namespace icl_core {
108 namespace crypt {
109 
111 typedef Sha2<uint32_t,
112  0xc1059ed8ul, 0x367cd507ul, 0x3070dd17ul, 0xf70e5939ul,
113  0xffc00b31ul, 0x68581511ul, 0x64f98fa7ul, 0xbefa4fa4ul, 7> Sha224;
115 typedef Sha2<uint32_t,
116  0x6a09e667ul, 0xbb67ae85ul, 0x3c6ef372ul, 0xa54ff53aul,
117  0x510e527ful, 0x9b05688cul, 0x1f83d9abul, 0x5be0cd19ul, 8> Sha256;
119 typedef Sha2<uint64_t,
120  0xcbbb9d5dc1059ed8ull, 0x629a292a367cd507ull, 0x9159015a3070dd17ull, 0x152fecd8f70e5939ull,
121  0x67332667ffc00b31ull, 0x8eb44a8768581511ull, 0xdb0c2e0d64f98fa7ull, 0x47b5481dbefa4fa4ull, 6> Sha384;
123 typedef Sha2<uint64_t,
124  0x6a09e667f3bcc908ull, 0xbb67ae8584caa73bull, 0x3c6ef372fe94f82bull, 0xa54ff53a5f1d36f1ull,
125  0x510e527fade682d1ull, 0x9b05688c2b3e6c1full, 0x1f83d9abfb41bd6bull, 0x5be0cd19137e2179ull, 8> Sha512;
126 
127 }
128 }
129 
130 #endif
void finalizeBuffer(size_t size)
unsigned int uint32_t
Definition: msvc_stdint.h:93
Sha2()
Initializes the internal state.
Sha2 & process(const ::icl_core::String &data)
Processes the string data.
Definition: Sha2.h:81
uint8_t m_buffer[cMESSAGE_BLOCK_SIZE]
Definition: Sha2Impl.h:84
::icl_core::String getHexDigest() const
Returns the message digest as a hex string.
T m_digest[8]
The whole message digest.
Definition: Sha2Impl.h:78
Sha2Impl< T, t_h0, t_h1, t_h2, t_h3, t_h4, t_h5, t_h6, t_h7, t_len > Impl
Definition: Sha2.h:69
Sha2< uint32_t, 0xc1059ed8ul, 0x367cd507ul, 0x3070dd17ul, 0xf70e5939ul, 0xffc00b31ul, 0x68581511ul, 0x64f98fa7ul, 0xbefa4fa4ul, 7 > Sha224
The SHA-224 hash algorithm.
Definition: Sha2.h:113
uint64_t m_message_size
The size of the message so far, in bytes.
Definition: Sha2Impl.h:80
Sha2 & finalize()
Finalizes the message digest.
size_t m_buffer_fill
The amount of bytes currently stored in the internal buffer.
Definition: Sha2Impl.h:86
Sha2< uint64_t, 0x6a09e667f3bcc908ull, 0xbb67ae8584caa73bull, 0x3c6ef372fe94f82bull, 0xa54ff53a5f1d36f1ull, 0x510e527fade682d1ull, 0x9b05688c2b3e6c1full, 0x1f83d9abfb41bd6bull, 0x5be0cd19137e2179ull, 8 > Sha512
The SHA-512 hash algorithm.
Definition: Sha2.h:125
Sha2< uint32_t, 0x6a09e667ul, 0xbb67ae85ul, 0x3c6ef372ul, 0xa54ff53aul, 0x510e527ful, 0x9b05688cul, 0x1f83d9abul, 0x5be0cd19ul, 8 > Sha256
The SHA-256 hash algorithm.
Definition: Sha2.h:117
unsigned __int64 uint64_t
Definition: msvc_stdint.h:103
Sha2 & process(const char *data)
Processes the string data.
static const size_t cMESSAGE_BLOCK_SIZE
The message block size in bytes.
Definition: Sha2Impl.h:56
std::string String
Definition: BaseTypes.h:43
void clear()
Clears the internal state. A new hash can then be calculated.
Contains Interface base classes and base types.
static const size_t cMESSAGE_PAD_POSITION
Definition: Sha2Impl.h:60
Sha2< uint64_t, 0xcbbb9d5dc1059ed8ull, 0x629a292a367cd507ull, 0x9159015a3070dd17ull, 0x152fecd8f70e5939ull, 0x67332667ffc00b31ull, 0x8eb44a8768581511ull, 0xdb0c2e0d64f98fa7ull, 0x47b5481dbefa4fa4ull, 6 > Sha384
The SHA-384 hash algorithm.
Definition: Sha2.h:121


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58