tmw/src/utils/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...

Defines

#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

typedef unsigned int uint32_t

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]


Define Documentation

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

Definition at line 99 of file sha256.cpp.

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

Definition at line 100 of file sha256.cpp.

#define PACK32 ( str,
 ) 

Value:

{                         \
    *(x) = ((uint32_t) *((str) + 3)      )     \
    | ((uint32_t) *((str) + 2) <<  8)     \
    | ((uint32_t) *((str) + 1) << 16)     \
    | ((uint32_t) *((str) + 0) << 24);    \
}

Definition at line 115 of file sha256.cpp.

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

Definition at line 98 of file sha256.cpp.

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

Definition at line 97 of file sha256.cpp.

#define SHA256_BLOCK_SIZE   (512 / 8)

Definition at line 82 of file sha256.cpp.

#define SHA256_DIGEST_SIZE   (256 / 8)

Definition at line 94 of file sha256.cpp.

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

Definition at line 102 of file sha256.cpp.

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

Definition at line 103 of file sha256.cpp.

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

Definition at line 104 of file sha256.cpp.

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

Definition at line 105 of file sha256.cpp.

#define SHA256_SCR (  ) 

Value:

{                         \
    w[i] =  SHA256_F4(w[i - 2]) + w[i - 7]     \
    + SHA256_F3(w[i - 15]) + w[i - 16];  \
}

Definition at line 125 of file sha256.cpp.

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

Definition at line 96 of file sha256.cpp.

#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);      \
}

Definition at line 107 of file sha256.cpp.


Typedef Documentation

typedef unsigned int uint32_t

Definition at line 79 of file sha256.cpp.


Function Documentation

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

Returns the SHA-256 hash for the given string.

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

Definition at line 273 of file sha256.cpp.

void SHA256Final ( SHA256Context ctx,
unsigned char *  digest 
)

Definition at line 241 of file sha256.cpp.

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

Definition at line 254 of file sha256.cpp.

void SHA256Init ( SHA256Context ctx  ) 

Definition at line 157 of file sha256.cpp.

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

Definition at line 165 of file sha256.cpp.

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

Definition at line 201 of file sha256.cpp.


Variable Documentation

const unsigned int sha256_h0[8]

Initial value:

{
    0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
    0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
}

Definition at line 131 of file sha256.cpp.

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 137 of file sha256.cpp.


Generated on Sun Apr 26 17:30:42 2009 for The Mana World by  doxygen 1.5.5