ndn-lite
Macros | Functions | Variables
tc_sha256.c File Reference
#include "tc_sha256.h"
#include "tc_constants.h"
#include "tc_utils.h"
#include <stdio.h>

Macros

#define Sigma0(a)   (ROTR((a), 2) ^ ROTR((a), 13) ^ ROTR((a), 22))
 
#define Sigma1(a)   (ROTR((a), 6) ^ ROTR((a), 11) ^ ROTR((a), 25))
 
#define sigma0(a)   (ROTR((a), 7) ^ ROTR((a), 18) ^ ((a) >> 3))
 
#define sigma1(a)   (ROTR((a), 17) ^ ROTR((a), 19) ^ ((a) >> 10))
 
#define Ch(a, b, c)   (((a) & (b)) ^ ((~(a)) & (c)))
 
#define Maj(a, b, c)   (((a) & (b)) ^ ((a) & (c)) ^ ((b) & (c)))
 

Functions

static void compress (unsigned int *iv, const uint8_t *data)
 
int tc_sha256_init (TCSha256State_t s)
 SHA256 initialization procedure Initializes s. More...
 
int tc_sha256_update (TCSha256State_t s, const uint8_t *data, size_t datalen)
 SHA256 update procedure Hashes data_length bytes addressed by data into state s. More...
 
int tc_sha256_final (uint8_t *digest, TCSha256State_t s)
 SHA256 final procedure Inserts the completed hash computation into digest. More...
 
static unsigned int ROTR (unsigned int a, unsigned int n)
 
static unsigned int BigEndian (const uint8_t **c)
 

Variables

static const unsigned int k256 [64]
 

Macro Definition Documentation

◆ Ch

#define Ch (   a,
  b,
 
)    (((a) & (b)) ^ ((~(a)) & (c)))

◆ Maj

#define Maj (   a,
  b,
 
)    (((a) & (b)) ^ ((a) & (c)) ^ ((b) & (c)))

◆ Sigma0

#define Sigma0 (   a)    (ROTR((a), 2) ^ ROTR((a), 13) ^ ROTR((a), 22))

◆ sigma0

#define sigma0 (   a)    (ROTR((a), 7) ^ ROTR((a), 18) ^ ((a) >> 3))

◆ Sigma1

#define Sigma1 (   a)    (ROTR((a), 6) ^ ROTR((a), 11) ^ ROTR((a), 25))

◆ sigma1

#define sigma1 (   a)    (ROTR((a), 17) ^ ROTR((a), 19) ^ ((a) >> 10))

Function Documentation

◆ BigEndian()

static unsigned int BigEndian ( const uint8_t **  c)
inlinestatic

◆ compress()

static void compress ( unsigned int *  iv,
const uint8_t *  data 
)
static

◆ ROTR()

static unsigned int ROTR ( unsigned int  a,
unsigned int  n 
)
inlinestatic

◆ tc_sha256_final()

int tc_sha256_final ( uint8_t *  digest,
TCSha256State_t  s 
)

SHA256 final procedure Inserts the completed hash computation into digest.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: s == NULL, s->iv == NULL, digest == NULL
Note
Assumes: s has been initialized by tc_sha256_init digest points to at least TC_SHA256_DIGEST_SIZE bytes
Warning
The state buffer 'leftover' is left in memory after processing If your application intends to have sensitive data in this buffer, remind to erase it after the data has been processed
Parameters
digestunsigned eight bit integer
Sha256state struct

◆ tc_sha256_init()

int tc_sha256_init ( TCSha256State_t  s)

SHA256 initialization procedure Initializes s.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if s == NULL
Parameters
sSha256 state struct

◆ tc_sha256_update()

int tc_sha256_update ( TCSha256State_t  s,
const uint8_t *  data,
size_t  datalen 
)

SHA256 update procedure Hashes data_length bytes addressed by data into state s.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: s == NULL, s->iv == NULL, data == NULL
Note
Assumes s has been initialized by tc_sha256_init
Warning
The state buffer 'leftover' is left in memory after processing If your application intends to have sensitive data in this buffer, remind to erase it after the data has been processed
Parameters
sSha256 state struct
datamessage to hash
datalenlength of message to hash

Variable Documentation

◆ k256

const unsigned int k256[64]
static
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
}