Loading...
Searching...
No Matches
sha512.hxx
Go to the documentation of this file.
#ifndef __DECAF_SHA512_HXX__
#define __DECAF_SHA512_HXX__
#include <decaf/secure_buffer.hxx>
#include <decaf/sha512.h>
#include <sys/types.h>
#if __cplusplus >= 201103L
#define DECAF_NOEXCEPT noexcept
#else
#define DECAF_NOEXCEPT throw()
#endif
namespace decaf {
class SHA512 {
protected:
decaf_sha512_ctx_t wrapped;
public:
static const size_t OUTPUT_BYTES = 64;
static const size_t MAX_OUTPUT_BYTES = OUTPUT_BYTES;
static const size_t DEFAULT_OUTPUT_BYTES = OUTPUT_BYTES;
inline SHA512() DECAF_NOEXCEPT { decaf_sha512_init(wrapped); }
inline void update(const uint8_t *__restrict__ in, size_t len) DECAF_NOEXCEPT { decaf_sha512_update(wrapped,in,len); }
inline void update(const Block &s) DECAF_NOEXCEPT { update(s.data(),s.size()); }
inline SHA512 &operator<<(const Block &s) { update(s); return *this; }
inline SHA512 &operator+=(const Block &s) { return *this << s; }
inline void final(Buffer b) /*throw(LengthException)*/ {
if (b.size() > OUTPUT_BYTES) throw LengthException();
decaf_sha512_final(wrapped,b.data(),b.size());
}
inline void reset() DECAF_NOEXCEPT { decaf_sha512_init(wrapped); }
inline SecureBuffer final(size_t len = OUTPUT_BYTES) /*throw(LengthException)*/ {
if (len > OUTPUT_BYTES) throw LengthException();
SecureBuffer buffer(len);
decaf_sha512_final(wrapped,buffer.data(),len);
return buffer;
}
inline size_t default_output_size() const DECAF_NOEXCEPT { return OUTPUT_BYTES; }
inline size_t max_output_size() const DECAF_NOEXCEPT { return MAX_OUTPUT_BYTES; }
static inline SecureBuffer hash (
const Block &message,
size_t outlen = OUTPUT_BYTES
) /*throw(LengthException, std::bad_alloc)*/ {
if (outlen > OUTPUT_BYTES) throw LengthException();
SecureBuffer buffer(outlen);
decaf_sha512_hash(buffer.data(),outlen,message.data(),message.size());
return buffer;
}
inline ~SHA512() DECAF_NOEXCEPT { decaf_sha512_destroy(wrapped); }
};
} /* namespace decaf */
#undef DECAF_NOEXCEPT
#endif /* __DECAF_SHA512_HXX__ */
decaf::Block
A reference to a block of data, which (when accessed through this base class) is const.
Definition secure_buffer.hxx:159
decaf::Block::data
const unsigned char * data() const DECAF_NOEXCEPT
Get const data.
Definition secure_buffer.hxx:199
decaf::Block::size
size_t size() const DECAF_NOEXCEPT
Get the size.
Definition secure_buffer.hxx:208
decaf::Buffer
A reference to a writable block of data.
Definition secure_buffer.hxx:270
decaf::FixedBlock
A fixed-size block.
Definition secure_buffer.hxx:253
decaf::LengthException
An exception for when crypto (ie point decode) has failed.
Definition secure_buffer.hxx:126
decaf::SHA512
SHA512 wrapper function.
Definition sha512.hxx:29
decaf::SHA512::operator<<
SHA512 & operator<<(const Block &s)
Add more data, stream version.
Definition sha512.hxx:56
decaf::SHA512::hash
static SecureBuffer hash(const Block &message, size_t outlen=OUTPUT_BYTES)
Hash a message in one pass.
Definition sha512.hxx:85
decaf::SHA512::reset
void reset() DECAF_NOEXCEPT
Resets the SHA context.
Definition sha512.hxx:68
decaf::SHA512::DEFAULT_OUTPUT_BYTES
static const size_t DEFAULT_OUTPUT_BYTES
Default number of bytes to output.
Definition sha512.hxx:44
decaf::SHA512::update
void update(const uint8_t *__restrict__ in, size_t len) DECAF_NOEXCEPT
Add more data to running hash.
Definition sha512.hxx:50
decaf::SHA512::update
void update(const Block &s) DECAF_NOEXCEPT
Add more data to running hash, C++ version.
Definition sha512.hxx:53
decaf::SHA512::max_output_size
size_t max_output_size() const DECAF_NOEXCEPT
Return the sponge's maximum output size.
Definition sha512.hxx:82
decaf::SHA512::~SHA512
~SHA512() DECAF_NOEXCEPT
Destructor zeroizes state.
Definition sha512.hxx:96
decaf::SHA512::OUTPUT_BYTES
static const size_t OUTPUT_BYTES
Number of bytes ouf output.
Definition sha512.hxx:38
decaf::SHA512::operator+=
SHA512 & operator+=(const Block &s)
Same as <<.
Definition sha512.hxx:59
decaf::SHA512::default_output_size
size_t default_output_size() const DECAF_NOEXCEPT
Return the sponge's default output size.
Definition sha512.hxx:79
decaf::SHA512::MAX_OUTPUT_BYTES
static const size_t MAX_OUTPUT_BYTES
Number of bytes of output.
Definition sha512.hxx:41
decaf::SHA512::SHA512
SHA512() DECAF_NOEXCEPT
Constructor.
Definition sha512.hxx:47
decaf
Namespace for all C++ decaf objects.
Definition decaf.hxx:22
decaf::SecureBuffer
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
secure_buffer.hxx
C++ self-zeroizing buffer.