GNU libmicrohttpd 1.0.1
Loading...
Searching...
No Matches
sha512_256.c File Reference

Calculation of SHA-512/256 digest as defined in FIPS PUB 180-4 (2015) More...

#include "sha512_256.h"
#include <string.h>
#include "mhd_bithelpers.h"
#include "mhd_assert.h"
Include dependency graph for sha512_256.c:

Go to the source code of this file.

Macros

#define Ch(x, y, z)
 
#define Maj(x, y, z)
 
#define SIG0(x)
 
#define SIG1(x)
 
#define sig0(x)
 
#define sig1(x)
 
#define SHA2STEP64(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt)
 
#define GET_W_FROM_DATA(buf, t)
 
#define Wgen(w, t)
 
#define SHA512_256_SIZE_OF_LEN_ADD_BITS   128
 
#define SHA512_256_SIZE_OF_LEN_ADD   (SHA512_256_SIZE_OF_LEN_ADD_BITS / 8)
 

Functions

void MHD_SHA512_256_init (struct Sha512_256Ctx *ctx)
 
static MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ void sha512_256_transform (uint64_t H[SHA512_256_HASH_SIZE_WORDS], const void *data)
 
void MHD_SHA512_256_update (struct Sha512_256Ctx *ctx, const uint8_t *data, size_t length)
 
void MHD_SHA512_256_finish (struct Sha512_256Ctx *ctx, uint8_t digest[SHA512_256_DIGEST_SIZE])
 

Detailed Description

Calculation of SHA-512/256 digest as defined in FIPS PUB 180-4 (2015)

Author
Karlson2k (Evgeny Grin)

Definition in file sha512_256.c.

Macro Definition Documentation

◆ Ch

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

◆ GET_W_FROM_DATA

#define GET_W_FROM_DATA ( buf,
t )
Value:
_MHD_GET_64BIT_BE (((const uint64_t*) (buf)) + (t))
#define _MHD_GET_64BIT_BE(addr)

◆ Maj

#define Maj ( x,
y,
z )
Value:
( ((x) & (y)) ^ ((z) & ((x) ^ (y))) )

◆ SHA2STEP64

#define SHA2STEP64 ( vA,
vB,
vC,
vD,
vE,
vF,
vG,
vH,
kt,
wt )
Value:
do { \
(vD) += ((vH) += SIG1 ((vE)) + Ch ((vE),(vF),(vG)) + (kt) + (wt)); \
(vH) += SIG0 ((vA)) + Maj ((vA),(vB),(vC)); } while (0)
#define Maj(x, y, z)
#define Ch(x, y, z)
#define SIG0(x)
#define SIG1(x)

Referenced by sha512_256_transform().

◆ SHA512_256_SIZE_OF_LEN_ADD

#define SHA512_256_SIZE_OF_LEN_ADD   (SHA512_256_SIZE_OF_LEN_ADD_BITS / 8)

Size of "length" insertion in bytes.

Definition at line 530 of file sha512_256.c.

Referenced by MHD_SHA512_256_finish().

◆ SHA512_256_SIZE_OF_LEN_ADD_BITS

#define SHA512_256_SIZE_OF_LEN_ADD_BITS   128

Size of "length" insertion in bits. See FIPS PUB 180-4 clause 5.1.2.

Definition at line 525 of file sha512_256.c.

◆ SIG0

#define SIG0 ( x)
Value:
( _MHD_ROTR64 ((x), 28) ^ _MHD_ROTR64 ((x), 34) ^ _MHD_ROTR64 ((x), 39) )
_MHD_static_inline uint64_t _MHD_ROTR64(uint64_t value64, int bits)

◆ sig0

#define sig0 ( x)
Value:
( _MHD_ROTR64 ((x), 1) ^ _MHD_ROTR64 ((x), 8) ^ ((x) >> 7) )

◆ SIG1

#define SIG1 ( x)
Value:
( _MHD_ROTR64 ((x), 14) ^ _MHD_ROTR64 ((x), 18) ^ _MHD_ROTR64 ((x), 41) )

◆ sig1

#define sig1 ( x)
Value:
( _MHD_ROTR64 ((x), 19) ^ _MHD_ROTR64 ((x), 61) ^ ((x) >> 6) )

◆ Wgen

#define Wgen ( w,
t )
Value:
( (w)[(t - 16) & 15] + sig1 ((w)[((t) - 2) & 15]) \
+ (w)[((t) - 7) & 15] + sig0 ((w)[((t) - 15) & 15]) )
#define sig1(x)
#define sig0(x)

Function Documentation

◆ MHD_SHA512_256_finish()

void MHD_SHA512_256_finish ( struct Sha512_256Ctx * ctx,
uint8_t digest[SHA512_256_DIGEST_SIZE] )

Finalise SHA-512/256 calculation, return digest.

Parameters
ctxthe calculation context
[out]digestset to the hash, must be SHA512_256_DIGEST_SIZE bytes

< Number of processed bits

< Number of bytes in the context buffer

Definition at line 539 of file sha512_256.c.

References _MHD_PUT_64BIT_BE, _MHD_UINT64_ALIGN, Sha512_256Ctx::buffer, Sha512_256Ctx::count, Sha512_256Ctx::count_bits_hi, Sha512_256Ctx::H, SHA512_256_BLOCK_SIZE, SHA512_256_BLOCK_SIZE_WORDS, SHA512_256_BYTES_IN_WORD, SHA512_256_DIGEST_SIZE, SHA512_256_DIGEST_SIZE_WORDS, SHA512_256_SIZE_OF_LEN_ADD, and sha512_256_transform().

Referenced by digest_calc_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_SHA512_256_init()

void MHD_SHA512_256_init ( struct Sha512_256Ctx * ctx)

Initialise structure for SHA-512/256 calculation.

Parameters
ctxthe calculation context

Definition at line 41 of file sha512_256.c.

References Sha512_256Ctx::count, Sha512_256Ctx::count_bits_hi, and Sha512_256Ctx::H.

Referenced by digest_init_one_time(), and digest_reset().

Here is the caller graph for this function:

◆ MHD_SHA512_256_update()

void MHD_SHA512_256_update ( struct Sha512_256Ctx * ctx,
const uint8_t * data,
size_t length )

Process portion of bytes.

Parameters
ctxthe calculation context
databytes to add to hash
lengthnumber of bytes in data

< Number of bytes in the context buffer

< The high part to be moved to another variable

Definition at line 460 of file sha512_256.c.

References Sha512_256Ctx::buffer, Sha512_256Ctx::count, Sha512_256Ctx::count_bits_hi, data, Sha512_256Ctx::H, mhd_assert, NULL, SHA512_256_BLOCK_SIZE, and sha512_256_transform().

Referenced by digest_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha512_256_transform()

static MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ void sha512_256_transform ( uint64_t H[SHA512_256_HASH_SIZE_WORDS],
const void * data )
static

Base of SHA-512/256 transformation. Gets full 128 bytes block of data and updates hash values;

Parameters
Hhash values
datathe data buffer with SHA512_256_BLOCK_SIZE bytes block

Definition at line 70 of file sha512_256.c.

References _MHD_UINT64_ALIGN, data, GET_W_FROM_DATA, SHA2STEP64, SHA512_256_HASH_SIZE_WORDS, and Wgen.

Referenced by MHD_SHA512_256_finish(), and MHD_SHA512_256_update().

Here is the caller graph for this function: