Version: SMASH-3.1
sha256.cc File Reference
#include "smash/sha256.h"
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>

Go to the source code of this file.

Namespaces

 smash
 
 smash::sha256
 

Macros

#define ror(value, bits)   (((value) >> (bits)) | ((value) << (32 - (bits))))
 
#define MIN(x, y)   (((x) < (y)) ? (x) : (y))
 
#define STORE32H(x, y)
 
#define LOAD32H(x, y)
 
#define STORE64H(x, y)
 
#define Ch(x, y, z)   (z ^ (x & (y ^ z)))
 
#define Maj(x, y, z)   (((x | y) & z) | (x & y))
 
#define S(x, n)   ror((x), (n))
 
#define R(x, n)   (((x)&0xFFFFFFFFUL) >> (n))
 
#define Sigma0(x)   (S(x, 2) ^ S(x, 13) ^ S(x, 22))
 
#define Sigma1(x)   (S(x, 6) ^ S(x, 11) ^ S(x, 25))
 
#define Gamma0(x)   (S(x, 7) ^ S(x, 18) ^ R(x, 3))
 
#define Gamma1(x)   (S(x, 17) ^ S(x, 19) ^ R(x, 10))
 
#define Sha256Round(a, b, c, d, e, f, g, h, i)
 

Functions

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

Variables

static const uint32_t K [64]
 The K array. More...
 
constexpr size_t smash::sha256::BLOCK_SIZE = 64
 

Macro Definition Documentation

◆ ror

#define ror (   value,
  bits 
)    (((value) >> (bits)) | ((value) << (32 - (bits))))

Definition at line 20 of file sha256.cc.

◆ MIN

#define MIN (   x,
 
)    (((x) < (y)) ? (x) : (y))

Definition at line 22 of file sha256.cc.

◆ STORE32H

#define STORE32H (   x,
 
)
Value:
{ \
(y)[0] = static_cast<uint8_t>(((x) >> 24) & 255); \
(y)[1] = static_cast<uint8_t>(((x) >> 16) & 255); \
(y)[2] = static_cast<uint8_t>(((x) >> 8) & 255); \
(y)[3] = static_cast<uint8_t>((x)&255); \
}

Definition at line 24 of file sha256.cc.

◆ LOAD32H

#define LOAD32H (   x,
 
)
Value:
{ \
x = (static_cast<uint32_t>((y)[0] & 255) << 24) | \
(static_cast<uint32_t>((y)[1] & 255) << 16) | \
(static_cast<uint32_t>((y)[2] & 255) << 8) | \
(static_cast<uint32_t>((y)[3] & 255)); \
}

Definition at line 32 of file sha256.cc.

◆ STORE64H

#define STORE64H (   x,
 
)
Value:
{ \
(y)[0] = static_cast<uint8_t>(((x) >> 56) & 255); \
(y)[1] = static_cast<uint8_t>(((x) >> 48) & 255); \
(y)[2] = static_cast<uint8_t>(((x) >> 40) & 255); \
(y)[3] = static_cast<uint8_t>(((x) >> 32) & 255); \
(y)[4] = static_cast<uint8_t>(((x) >> 24) & 255); \
(y)[5] = static_cast<uint8_t>(((x) >> 16) & 255); \
(y)[6] = static_cast<uint8_t>(((x) >> 8) & 255); \
(y)[7] = static_cast<uint8_t>((x)&255); \
}

Definition at line 40 of file sha256.cc.

◆ Ch

#define Ch (   x,
  y,
 
)    (z ^ (x & (y ^ z)))

Definition at line 52 of file sha256.cc.

◆ Maj

#define Maj (   x,
  y,
 
)    (((x | y) & z) | (x & y))

Definition at line 53 of file sha256.cc.

◆ S

#define S (   x,
 
)    ror((x), (n))

Definition at line 54 of file sha256.cc.

◆ R

#define R (   x,
 
)    (((x)&0xFFFFFFFFUL) >> (n))

Definition at line 55 of file sha256.cc.

◆ Sigma0

#define Sigma0 (   x)    (S(x, 2) ^ S(x, 13) ^ S(x, 22))

Definition at line 56 of file sha256.cc.

◆ Sigma1

#define Sigma1 (   x)    (S(x, 6) ^ S(x, 11) ^ S(x, 25))

Definition at line 57 of file sha256.cc.

◆ Gamma0

#define Gamma0 (   x)    (S(x, 7) ^ S(x, 18) ^ R(x, 3))

Definition at line 58 of file sha256.cc.

◆ Gamma1

#define Gamma1 (   x)    (S(x, 17) ^ S(x, 19) ^ R(x, 10))

Definition at line 59 of file sha256.cc.

◆ Sha256Round

#define Sha256Round (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
 
)
Value:
t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
t1 = Sigma0(a) + Maj(a, b, c); \
d += t0; \
h = t0 + t1;
static const uint32_t K[64]
The K array.
Definition: sha256.cc:70
#define Maj(x, y, z)
Definition: sha256.cc:53
#define Sigma0(x)
Definition: sha256.cc:56
#define Sigma1(x)
Definition: sha256.cc:57
#define Ch(x, y, z)
Definition: sha256.cc:52

Definition at line 61 of file sha256.cc.

Variable Documentation

◆ K

const uint32_t K[64]
static
Initial value:
= {
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL}

The K array.

Definition at line 70 of file sha256.cc.