sha256.c File Reference


Data Structures

struct  sha256_state

Defines

#define CRYPT_OK   0
#define CRYPT_NOP   -1
#define CRYPT_INVALID_ARG   -2
#define LOAD32H(x, y)   STMT_BEGIN x = ntohl(get_uint32((const char*)y)); STMT_END
#define STORE32H(x, y)   STMT_BEGIN set_uint32((char*)y, htonl(x)); STMT_END
#define STORE64H(x, y)
#define RORc(x, y)   ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
#define MIN(x, y)   ( ((x)<(y))?(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)   RORc((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 RND(a, b, c, d, e, f, g, h, i, ki)

Functions

static int sha256_compress (sha256_state *md, unsigned char *buf)
static int sha256_init (sha256_state *md)
static int sha256_process (sha256_state *md, const unsigned char *in, unsigned long inlen)
static int sha256_done (sha256_state *md, unsigned char *out)

Detailed Description

SHA256 by Tom St Denis

Define Documentation

#define RND ( a,
b,
c,
d,
e,
f,
g,
h,
i,
ki   ) 

Value:

t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i];   \
     t1 = Sigma0(a) + Maj(a, b, c);                  \
     d += t0;                                        \
     h  = t0 + t1;

#define STORE64H ( x,
 ) 

Value:

STMT_BEGIN                                \
  set_uint32((char*)y, htonl((uint32_t)((x)>>32)));             \
  set_uint32(((char*)y)+4, htonl((uint32_t)((x)&0xffffffff)));  \
  STMT_END


Function Documentation

static int sha256_done ( sha256_state *  md,
unsigned char *  out 
) [static]

Terminate the hash to get the digest

Parameters:
md The hash state
out [out] The destination of the hash (32 bytes)
Returns:
CRYPT_OK if successful

static int sha256_init ( sha256_state *  md  )  [static]

Initialize the hash state

Parameters:
md The hash state you wish to initialize
Returns:
CRYPT_OK if successful

static int sha256_process ( sha256_state *  md,
const unsigned char *  in,
unsigned long  inlen 
) [static]

Process a block of memory though the hash

Parameters:
md The hash state
in The data to hash
inlen The length of the data (octets)
Returns:
CRYPT_OK if successful


Generated on Tue May 25 00:30:59 2010 for tor by  doxygen 1.5.6