11 #ifndef __DECAF_SHAKE_HXX__ 12 #define __DECAF_SHAKE_HXX__ 16 #include <sys/types.h> 19 #if __cplusplus >= 201103L 20 #define DECAF_NOEXCEPT noexcept 21 #define DECAF_DELETE = delete 23 #define DECAF_NOEXCEPT throw() 126 static inline const struct decaf_kparams_s *get_params();
130 static const size_t MAX_OUTPUT_BYTES = bits/8;
133 static const size_t DEFAULT_OUTPUT_BYTES = bits/8;
142 if (nbytes > MAX_OUTPUT_BYTES) {
154 static inline const struct decaf_kparams_s *get_params();
158 #if __cplusplus >= 201103L 159 static const size_t MAX_OUTPUT_BYTES = SIZE_MAX;
161 static const size_t MAX_OUTPUT_BYTES = (size_t)-1;
165 static const size_t DEFAULT_OUTPUT_BYTES = bits/4;
177 #if defined _MSC_VER // MSVC does not want tempalte<> syntax, gcc cannot live without it 188 template<>
inline const struct decaf_kparams_s *
SHAKE<128>::get_params() {
return &DECAF_SHAKE128_params_s; }
189 template<>
inline const struct decaf_kparams_s *
SHAKE<256>::get_params() {
return &DECAF_SHAKE256_params_s; }
190 template<>
inline const struct decaf_kparams_s *
SHA3<224>::get_params() {
return &DECAF_SHA3_224_params_s; }
191 template<>
inline const struct decaf_kparams_s *
SHA3<256>::get_params() {
return &DECAF_SHA3_256_params_s; }
192 template<>
inline const struct decaf_kparams_s *
SHA3<384>::get_params() {
return &DECAF_SHA3_384_params_s; }
193 template<>
inline const struct decaf_kparams_s *
SHA3<512>::get_params() {
return &DECAF_SHA3_512_params_s; }
200 #undef DECAF_NOEXCEPT KeccakHash & operator+=(const Block &s) DECAF_NOEXCEPT
Same as <<.
Definition: shake.hxx:55
size_t default_output_size() const DECAF_NOEXCEPT
Return the sponge's default output size.
Definition: shake.hxx:96
decaf_error_t DECAF_API_VIS decaf_sha3_output(decaf_keccak_sponge_t sponge, uint8_t *__restrict__ out, size_t len)
Squeeze output data from a DECAF_SHA3 or DECAF_SHAKE hash context.
size_t DECAF_API_VIS decaf_sha3_max_output_bytes(const decaf_keccak_sponge_t sponge)
Return the default output length of the sponge construction, for the purpose of C++ default operators...
void reset() DECAF_NOEXCEPT
Reset the hash to the empty string.
Definition: shake.hxx:116
KeccakHash & operator<<(const Block &s) DECAF_NOEXCEPT
Add more data, stream version.
Definition: shake.hxx:52
size_t max_output_size() const DECAF_NOEXCEPT
Return the sponge's maximum output size.
Definition: shake.hxx:101
void output(Buffer b)
Output bytes from the sponge.
Definition: shake.hxx:80
A reference to a writable block of data.
Definition: secure_buffer.hxx:264
SecureBuffer output(size_t len)
Output bytes from the sponge.
Definition: shake.hxx:58
Variable-output-length SHAKE.
Definition: shake.hxx:151
void update(const Block &s) DECAF_NOEXCEPT
Add more data to running hash, C++ version.
Definition: shake.hxx:49
An exception for when crypto (ie point decode) has failed.
Definition: secure_buffer.hxx:126
The operation succeeded.
Definition: common.h:121
~KeccakHash() DECAF_NOEXCEPT
Destructor zeroizes state.
Definition: shake.hxx:119
Fixed-output-length SHA3.
Definition: shake.hxx:123
struct decaf_keccak_sponge_s decaf_keccak_sponge_t[1]
Convenience GMP-style one-element array version.
Definition: shake.h:33
std::vector< unsigned char, SanitizingAllocator< unsigned char, 0 > > SecureBuffer
A variant of std::vector which securely zerozes its state when destructed.
Definition: secure_buffer.hxx:79
void DECAF_API_VIS decaf_sha3_init(decaf_keccak_sponge_t sponge, const struct decaf_kparams_s *params)
Initialize a sponge context object.
static SecureBuffer hash(const Block &b, size_t outlen)
Hash bytes with this SHAKE instance.
Definition: shake.hxx:171
void update(const uint8_t *__restrict__ in, size_t len) DECAF_NOEXCEPT
Add more data to running hash.
Definition: shake.hxx:46
SHA3() DECAF_NOEXCEPT
Initializer.
Definition: shake.hxx:136
Hash function derived from Keccak FUTURE: throw ProtocolException when hash is misused by calling upd...
Definition: shake.hxx:34
const unsigned char * data() const DECAF_NOEXCEPT
Get const data.
Definition: secure_buffer.hxx:276
A reference to a block of data, which (when accessed through this base class) is const.
Definition: secure_buffer.hxx:159
void DECAF_API_VIS decaf_sha3_reset(decaf_keccak_sponge_t sponge)
Reset the sponge to the empty string.
C++ self-zeroizing buffer.
static SecureBuffer hash(const Block &b, size_t nbytes=MAX_OUTPUT_BYTES)
Hash bytes with this SHA3 instance.
Definition: shake.hxx:141
decaf_error_t DECAF_API_VIS decaf_sha3_update(struct decaf_keccak_sponge_s *__restrict__ sponge, const uint8_t *in, size_t len)
Absorb data into a DECAF_SHA3 or DECAF_SHAKE hash context.
size_t DECAF_API_VIS decaf_sha3_default_output_bytes(const decaf_keccak_sponge_t sponge)
Return the default output length of the sponge construction, for the purpose of C++ default operators...
SHAKE() DECAF_NOEXCEPT
Initializer.
Definition: shake.hxx:168
SecureBuffer output()
Output the default number of bytes.
Definition: shake.hxx:106
decaf_error_t DECAF_API_VIS decaf_sha3_final(decaf_keccak_sponge_t sponge, uint8_t *__restrict__ out, size_t len)
Squeeze output data from a DECAF_SHA3 or DECAF_SHAKE hash context.
void DECAF_API_VIS decaf_sha3_destroy(decaf_keccak_sponge_t sponge)
Destroy a DECAF_SHA3 or DECAF_SHAKE sponge context by overwriting it with 0.
Namespace for all libdecaf C++ objects.
Definition: ed255.hxx:41
size_t size() const DECAF_NOEXCEPT
Get the size.
Definition: secure_buffer.hxx:202