GNU libmicrohttpd 0.9.77
Loading...
Searching...
No Matches
sha1.c File Reference

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

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

Go to the source code of this file.

Macros

#define Ch(x, y, z)   ( (z) ^ ((x) & ((y) ^ (z))) )
 
#define Maj(x, y, z)   ( ((x) & (y)) ^ ((z) & ((x) ^ (y))) )
 
#define Par(x, y, z)   ( (x) ^ (y) ^ (z) )
 
#define SHA1STEP32(vA, vB, vC, vD, vE, ft, kt, wt)
 
#define GET_W_FROM_DATA(buf, t)    _MHD_GET_32BIT_BE (((const uint8_t*) (buf)) + (t) * SHA1_BYTES_IN_WORD)
 
#define K00   UINT32_C(0x5a827999)
 
#define K20   UINT32_C(0x6ed9eba1)
 
#define K40   UINT32_C(0x8f1bbcdc)
 
#define K60   UINT32_C(0xca62c1d6)
 
#define Wgen(w, t)
 
#define SHA1_SIZE_OF_LEN_ADD   (64 / 8)
 

Functions

void MHD_SHA1_init (void *ctx_)
 
static void sha1_transform (uint32_t H[_SHA1_DIGEST_LENGTH], const uint8_t data[SHA1_BLOCK_SIZE])
 
void MHD_SHA1_update (void *ctx_, const uint8_t *data, size_t length)
 
void MHD_SHA1_finish (void *ctx_, uint8_t digest[SHA1_DIGEST_SIZE])
 

Detailed Description

Calculation of SHA-1 digest as defined in FIPS PUB 180-4 (2015)

Author
Karlson2k (Evgeny Grin)

Definition in file sha1.c.

Macro Definition Documentation

◆ Ch

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

◆ GET_W_FROM_DATA

#define GET_W_FROM_DATA (   buf,
 
)     _MHD_GET_32BIT_BE (((const uint8_t*) (buf)) + (t) * SHA1_BYTES_IN_WORD)

◆ K00

#define K00   UINT32_C(0x5a827999)

◆ K20

#define K20   UINT32_C(0x6ed9eba1)

◆ K40

#define K40   UINT32_C(0x8f1bbcdc)

◆ K60

#define K60   UINT32_C(0xca62c1d6)

◆ Maj

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

◆ Par

#define Par (   x,
  y,
 
)    ( (x) ^ (y) ^ (z) )

◆ SHA1_SIZE_OF_LEN_ADD

#define SHA1_SIZE_OF_LEN_ADD   (64 / 8)

Size of "length" padding addition in bytes. See FIPS PUB 180-4 paragraph 5.1.1.

Definition at line 302 of file sha1.c.

◆ SHA1STEP32

#define SHA1STEP32 (   vA,
  vB,
  vC,
  vD,
  vE,
  ft,
  kt,
  wt 
)
Value:
do { \
(vE) += _MHD_ROTL32 ((vA), 5) + ft ((vB), (vC), (vD)) + (kt) + (wt); \
(vB) = _MHD_ROTL32 ((vB), 30); } while (0)
_MHD_static_inline uint32_t _MHD_ROTL32(uint32_t value32, int bits)

◆ Wgen

#define Wgen (   w,
 
)
Value:
_MHD_ROTL32((w)[(t + 13) & 0xf] ^ (w)[(t + 8) & 0xf] \
^ (w)[(t + 2) & 0xf] ^ (w)[t & 0xf], 1)

Function Documentation

◆ MHD_SHA1_finish()

void MHD_SHA1_finish ( void *  ctx_,
uint8_t  digest[SHA1_DIGEST_SIZE] 
)

Finalise SHA-1 calculation, return digest.

Parameters
ctx_must be a struct sha1_ctx *
[out]digestset to the hash, must be SHA1_DIGEST_SIZE bytes

< Number of processed bits

< Number of bytes in buffer

Definition at line 311 of file sha1.c.

References _MHD_PUT_32BIT_BE, _MHD_PUT_64BIT_BE_SAFE(), _MHD_UINT32_ALIGN, _SHA1_DIGEST_LENGTH, sha1_ctx::buffer, sha1_ctx::count, sha1_ctx::H, SHA1_BLOCK_SIZE, SHA1_BYTES_IN_WORD, SHA1_DIGEST_SIZE, SHA1_SIZE_OF_LEN_ADD, and sha1_transform().

Referenced by MHD_websocket_create_accept_header().

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

◆ MHD_SHA1_init()

void MHD_SHA1_init ( void *  ctx_)

Initialise structure for SHA-1 calculation.

Parameters
ctx_must be a struct sha1_ctx *

Definition at line 41 of file sha1.c.

References sha1_ctx::count, and sha1_ctx::H.

Referenced by MHD_websocket_create_accept_header().

Here is the caller graph for this function:

◆ MHD_SHA1_update()

void MHD_SHA1_update ( void *  ctx_,
const uint8_t *  data,
size_t  length 
)

Process portion of bytes.

Parameters
ctx_must be a struct sha1_ctx *
databytes to add to hash
lengthnumber of bytes in data

< Number of bytes in buffer

Definition at line 249 of file sha1.c.

References sha1_ctx::buffer, sha1_ctx::count, data, sha1_ctx::H, mhd_assert, NULL, SHA1_BLOCK_SIZE, and sha1_transform().

Referenced by MHD_websocket_create_accept_header().

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

◆ sha1_transform()

static void sha1_transform ( uint32_t  H[_SHA1_DIGEST_LENGTH],
const uint8_t  data[SHA1_BLOCK_SIZE] 
)
static

Base of SHA-1 transformation. Gets full 512 bits / 64 bytes block of data and updates hash values;

Parameters
Hhash values
datadata, must be exactly 64 bytes long

Definition at line 64 of file sha1.c.

References _MHD_UINT32_ALIGN, Ch, data, GET_W_FROM_DATA, sha1_ctx::H, K00, K20, K40, K60, Maj, Par, SHA1_BLOCK_SIZE, SHA1STEP32, and Wgen.

Referenced by MHD_SHA1_finish(), and MHD_SHA1_update().

Here is the caller graph for this function: