CatapultServer  v0.5.0.1 (Elephant)
Hashes.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/types.h"
23 
24 namespace catapult { namespace crypto {
25 
26  // region free functions
27 
29  void Ripemd160(const RawBuffer& dataBuffer, Hash160& hash) noexcept;
30 
32  void Bitcoin160(const RawBuffer& dataBuffer, Hash160& hash) noexcept;
33 
35  void Sha256Double(const RawBuffer& dataBuffer, Hash256& hash) noexcept;
36 
38  void Sha3_256(const RawBuffer& dataBuffer, Hash256& hash) noexcept;
39 
41  void Sha3_512(const RawBuffer& dataBuffer, Hash512& hash) noexcept;
42 
44  void Keccak_256(const RawBuffer& dataBuffer, Hash256& hash) noexcept;
45 
47  void Keccak_512(const RawBuffer& dataBuffer, Hash512& hash) noexcept;
48 
49  // endregion
50 
51  // region sha3 / keccak builders
52 
54  struct Sha3ModeTag {};
55 
57  struct KeccakModeTag {};
58 
60  template<typename TModeTag, typename THashTag>
61  class alignas(32) KeccakBuilder {
62  public:
64 
65  public:
67  KeccakBuilder();
68 
69  public:
71  void update(const RawBuffer& dataBuffer) noexcept;
72 
74  void update(std::initializer_list<const RawBuffer> buffers) noexcept;
75 
77  void final(OutputType& output) noexcept;
78 
79  private:
80  // size below is related to amount of data Keccak needs for its internal state
81  uint8_t m_hashContext[256];
82  };
83 
86  extern template class KeccakBuilder<Sha3ModeTag, Hash256_tag>;
87 
90  extern template class KeccakBuilder<Sha3ModeTag, Hash512_tag>;
91 
94  extern template class KeccakBuilder<KeccakModeTag, Hash256_tag>;
95 
98  extern template class KeccakBuilder<KeccakModeTag, Hash512_tag>;
99 
103 
104  // endregion
105 }}
catapult::crypto::Sha256Double
void Sha256Double(const RawBuffer &dataBuffer, Hash256 &hash) noexcept
Calculates double sha256 hash of dataBuffer into hash.
Definition: Hashes.cpp:65
KeccakHash.h
catapult::crypto::Keccak_512
void Keccak_512(const RawBuffer &dataBuffer, Hash512 &hash) noexcept
Calculates the 512-bit Keccak hash of dataBuffer into hash.
Definition: Hashes.cpp:93
catapult::Hash256
utils::ByteArray< Hash256_Size, Hash256_tag > Hash256
Definition: src/catapult/types.h:47
catapult::crypto::Sha3_256
void Sha3_256(const RawBuffer &dataBuffer, Hash256 &hash) noexcept
Calculates the 256-bit SHA3 hash of dataBuffer into hash.
Definition: Hashes.cpp:81
catapult::crypto::Sha3_512
void Sha3_512(const RawBuffer &dataBuffer, Hash512 &hash) noexcept
Calculates the 512-bit SHA3 hash of dataBuffer into hash.
Definition: Hashes.cpp:85
catapult::crypto::KeccakBuilder
Builder for building a hash.
Definition: Hashes.h:61
catapult::utils::ByteArray::data
constexpr const uint8_t * data() const noexcept
Returns a const pointer to the underlying array.
Definition: ByteArray.h:70
catapult::Hash160_Size
constexpr size_t Hash160_Size
Definition: src/catapult/types.h:35
catapult::crypto::KeccakBuilder::final
void final(OutputType &output) noexcept
Finalize hash calculation. Returns result in output.
Definition: Hashes.cpp:145
Hashes.h
catapult::crypto::Bitcoin160
void Bitcoin160(const RawBuffer &dataBuffer, Hash160 &hash) noexcept
Calculates bitcoin's hash 160 of dataBuffer into hash (sha256 + ripemd).
Definition: Hashes.cpp:58
catapult::crypto::KeccakBuilder::update
void update(const RawBuffer &dataBuffer) noexcept
Updates the state of hash with data inside dataBuffer.
Definition: Hashes.cpp:134
catapult::crypto::KeccakModeTag
Use with KeccakBuilder to generate Keccak hashes.
Definition: Hashes.h:57
catapult::crypto::KeccakBuilder::m_hashContext
uint8_t m_hashContext[256]
Definition: Hashes.h:81
catapult::Hash512
utils::ByteArray< Hash512_Size, Hash512_tag > Hash512
Definition: src/catapult/types.h:44
types.h
Casting.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::ByteArray
Base class for wrappers of byte array types, to provide some type-safety.
Definition: ByteArray.h:29
catapult::crypto::KeccakBuilder::KeccakBuilder
KeccakBuilder()
Creates a builder.
Definition: Hashes.cpp:128
catapult::Hash160
utils::ByteArray< Hash160_Size, Hash160_tag > Hash160
Definition: src/catapult/types.h:50
catapult::crypto::Keccak_256
void Keccak_256(const RawBuffer &dataBuffer, Hash256 &hash) noexcept
Calculates the 256-bit Keccak hash of dataBuffer into hash.
Definition: Hashes.cpp:89
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62
catapult::crypto::Sha3ModeTag
Use with KeccakBuilder to generate SHA3 hashes.
Definition: Hashes.h:54
catapult::crypto::Ripemd160
void Ripemd160(const RawBuffer &dataBuffer, Hash160 &hash) noexcept
Calculates the ripemd160 hash of dataBuffer into hash.
Definition: Hashes.cpp:44