Ring Daemon 16.0.0
Loading...
Searching...
No Matches
SHA3.h
Go to the documentation of this file.
1/*
2 This file is part of cpp-ethereum.
3
4 cpp-ethereum is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 cpp-ethereum is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16*/
24#pragma once
25
26#include <string>
27#include "FixedHash.h"
28#include "vector_ref.h"
29
30namespace dev {
31
32// SHA-3 convenience routines.
33
36bool sha3(bytesConstRef _input, bytesRef o_output);
37
39inline h256
41{
42 h256 ret;
43 sha3(_input, ret.ref());
44 return ret;
45}
46
48inline h256
49sha3(bytes const& _input)
50{
51 return sha3(bytesConstRef(&_input));
52}
53
56inline h256
57sha3(std::string const& _input)
58{
59 return sha3(bytesConstRef(_input));
60}
61
63template<unsigned N>
64inline h256
65sha3(FixedHash<N> const& _input)
66{
67 return sha3(_input.ref());
68}
69
72inline std::string
73sha3(std::string const& _input, bool _isNibbles)
74{
75 return asString((_isNibbles ? sha3(fromHex(_input)) : sha3(bytesConstRef(&_input))).asBytes());
76}
77
78} // namespace dev
bytesRef ref()
Definition FixedHash.h:209
A modifiable reference to an existing object or vector in memory.
Definition vector_ref.h:21
Definition Address.h:25
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
Definition SHA3.cpp:196
vector_ref< uint8_t const > bytesConstRef
vector_ref< uint8_t > bytesRef
std::vector< uint8_t > bytes
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
Definition CommonData.h:101
FixedHash< 32 > h256
Definition FixedHash.h:493
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
Definition CommonData.h:116