Version: SMASH-3.1
smash::sha256 Namespace Reference

Classes

class  Context
 A SHA256 context. More...
 

Typedefs

typedef std::array< uint8_t, HASH_SIZEHash
 A SHA256 hash. More...
 

Functions

Hash calculate (uint8_t const *buffer, size_t buffer_size)
 Calculate the SHA256 hash of the buffer. More...
 
std::string hash_to_string (Hash hash)
 Convert a SHA256 hash to a hexadecimal string. More...
 

Variables

constexpr size_t HASH_SIZE = 256 / 8
 Size of a SHA256 hash. More...
 
constexpr size_t BLOCK_SIZE = 64
 

Typedef Documentation

◆ Hash

typedef std::array<uint8_t, HASH_SIZE> smash::sha256::Hash

A SHA256 hash.

Definition at line 25 of file sha256.h.

Function Documentation

◆ calculate()

Hash smash::sha256::calculate ( uint8_t const *  buffer,
size_t  buffer_size 
)

Calculate the SHA256 hash of the buffer.

Definition at line 224 of file sha256.cc.

224  {
225  Context context;
226  context.update(buffer, buffer_size);
227  return context.finalize();
228 }

◆ hash_to_string()

std::string smash::sha256::hash_to_string ( Hash  hash)

Convert a SHA256 hash to a hexadecimal string.

Definition at line 230 of file sha256.cc.

230  {
231  std::stringstream ss;
232  ss << std::hex;
233  for (uint16_t i : hash) {
234  ss << std::setw(2) << std::setfill('0') << i;
235  }
236  return ss.str();
237 }

Variable Documentation

◆ HASH_SIZE

constexpr size_t smash::sha256::HASH_SIZE = 256 / 8
constexpr

Size of a SHA256 hash.

Definition at line 22 of file sha256.h.

◆ BLOCK_SIZE

constexpr size_t smash::sha256::BLOCK_SIZE = 64
constexpr

Definition at line 88 of file sha256.cc.