Mana
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
sha256.cpp File Reference
#include "utils/sha256.h"
#include <memory.h>

Go to the source code of this file.

Classes

class  SHA256Context
 An sha 256 context, used by original m_opersha256. More...
 

Macros

#define SHA256_BLOCK_SIZE   (512 / 8)
 
#define SHA256_DIGEST_SIZE   (256 / 8)
 
#define SHFR(x, n)   (x >> n)
 
#define ROTR(x, n)   ((x >> n) | (x << ((sizeof(x) << 3) - n)))
 
#define ROTL(x, n)   ((x << n) | (x >> ((sizeof(x) << 3) - n)))
 
#define CH(x, y, z)   ((x & y) ^ (~x & z))
 
#define MAJ(x, y, z)   ((x & y) ^ (x & z) ^ (y & z))
 
#define SHA256_F1(x)   (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
 
#define SHA256_F2(x)   (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
 
#define SHA256_F3(x)   (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3))
 
#define SHA256_F4(x)   (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10))
 
#define UNPACK32(x, str)
 
#define PACK32(str, x)
 
#define SHA256_SCR(i)
 

Typedefs

using uint8_t = unsigned char
 
using uint32_t = unsigned int
 

Functions

void SHA256Init (SHA256Context *ctx)
 
void SHA256Transform (SHA256Context *ctx, unsigned char *message, unsigned int block_nb)
 
void SHA256Update (SHA256Context *ctx, unsigned char *message, unsigned int len)
 
void SHA256Final (SHA256Context *ctx, unsigned char *digest)
 
std::string SHA256Hash (const char *src, int len)
 
std::string sha256 (const std::string &string)
 Returns the SHA-256 hash for the given string.
 

Variables

const unsigned int sha256_h0 [8]
 
uint32_t sha256_k [64]
 

Macro Definition Documentation

◆ CH

#define CH (   x,
  y,
 
)    ((x & y) ^ (~x & z))

Definition at line 102 of file sha256.cpp.

◆ MAJ

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

Definition at line 103 of file sha256.cpp.

◆ PACK32

#define PACK32 (   str,
 
)
Value:
{ \
*(x) = ((uint32_t) *((str) + 3) ) \
| ((uint32_t) *((str) + 2) << 8) \
| ((uint32_t) *((str) + 1) << 16) \
| ((uint32_t) *((str) + 0) << 24); \
}
unsigned int uint32_t
Definition sha256.cpp:82

Definition at line 118 of file sha256.cpp.

◆ ROTL

#define ROTL (   x,
 
)    ((x << n) | (x >> ((sizeof(x) << 3) - n)))

Definition at line 101 of file sha256.cpp.

◆ ROTR

#define ROTR (   x,
 
)    ((x >> n) | (x << ((sizeof(x) << 3) - n)))

Definition at line 100 of file sha256.cpp.

◆ SHA256_BLOCK_SIZE

#define SHA256_BLOCK_SIZE   (512 / 8)

Definition at line 85 of file sha256.cpp.

◆ SHA256_DIGEST_SIZE

#define SHA256_DIGEST_SIZE   (256 / 8)

Definition at line 97 of file sha256.cpp.

◆ SHA256_F1

#define SHA256_F1 (   x)    (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))

Definition at line 105 of file sha256.cpp.

◆ SHA256_F2

#define SHA256_F2 (   x)    (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))

Definition at line 106 of file sha256.cpp.

◆ SHA256_F3

#define SHA256_F3 (   x)    (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3))

Definition at line 107 of file sha256.cpp.

◆ SHA256_F4

#define SHA256_F4 (   x)    (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10))

Definition at line 108 of file sha256.cpp.

◆ SHA256_SCR

#define SHA256_SCR (   i)
Value:
{ \
w[i] = SHA256_F4(w[i - 2]) + w[i - 7] \
+ SHA256_F3(w[i - 15]) + w[i - 16]; \
}
#define SHA256_F3(x)
Definition sha256.cpp:107
#define SHA256_F4(x)
Definition sha256.cpp:108

Definition at line 128 of file sha256.cpp.

◆ SHFR

#define SHFR (   x,
 
)    (x >> n)

Definition at line 99 of file sha256.cpp.

◆ UNPACK32

#define UNPACK32 (   x,
  str 
)
Value:
{ \
*((str) + 3) = (uint8_t) ((x) ); \
*((str) + 2) = (uint8_t) ((x) >> 8); \
*((str) + 1) = (uint8_t) ((x) >> 16); \
*((str) + 0) = (uint8_t) ((x) >> 24); \
}
unsigned char uint8_t
Definition sha256.cpp:81

Definition at line 110 of file sha256.cpp.

Typedef Documentation

◆ uint32_t

using uint32_t = unsigned int

Definition at line 82 of file sha256.cpp.

◆ uint8_t

using uint8_t = unsigned char

Definition at line 81 of file sha256.cpp.

Function Documentation

◆ sha256()

std::string sha256 ( const std::string &  string)

Returns the SHA-256 hash for the given string.

Parameters
stringthe string to create the SHA-256 hash for
Returns
the SHA-256 hash for the given string.

Definition at line 276 of file sha256.cpp.

◆ SHA256Final()

void SHA256Final ( SHA256Context ctx,
unsigned char *  digest 
)

Definition at line 244 of file sha256.cpp.

◆ SHA256Hash()

std::string SHA256Hash ( const char *  src,
int  len 
)

Definition at line 257 of file sha256.cpp.

◆ SHA256Init()

void SHA256Init ( SHA256Context ctx)

Definition at line 160 of file sha256.cpp.

◆ SHA256Transform()

void SHA256Transform ( SHA256Context ctx,
unsigned char *  message,
unsigned int  block_nb 
)

Definition at line 168 of file sha256.cpp.

◆ SHA256Update()

void SHA256Update ( SHA256Context ctx,
unsigned char *  message,
unsigned int  len 
)

Definition at line 204 of file sha256.cpp.

Variable Documentation

◆ sha256_h0

const unsigned int sha256_h0[8]
Initial value:
=
{
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
}

Definition at line 134 of file sha256.cpp.

◆ sha256_k

uint32_t sha256_k[64]
Initial value:
=
{
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
}

Definition at line 140 of file sha256.cpp.