rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
link_sha256.c File Reference

SHA-256, written from FIPS 180-4: the constants of section 4.2.2, the initial hash value of section 5.3.3, the padding of section 5.1.1 and the computation of section 6.2.2. More...

#include "link_sha256.h"
#include <string.h>

Functions

static uint32_t rotr (uint32_t x, unsigned n)
 Rotate a 32-bit word right.
static void compress (uint32_t h[8], const uint8_t block[64])
 One 512-bit block (section 6.2.2, steps 1 to 4).
void link_sha256_init (link_sha256_t *s)
 Start a computation: set the initial hash value and clear the state.
void link_sha256_update (link_sha256_t *s, const void *data, size_t len)
 Fold len bytes in. data may be NULL when len is 0.
void link_sha256_final (link_sha256_t *s, uint8_t out[LINK_SHA256_BYTES])
 Pad, finish and write the 32-byte digest. s is spent afterwards.
void link_sha256 (const void *data, size_t len, uint8_t out[LINK_SHA256_BYTES])
 The digest of len bytes in one call.

Variables

static const uint32_t k_round [64]
 The first 32 bits of the fractional parts of the cube roots of the first 64 primes (section 4.2.2).

Detailed Description

SHA-256, written from FIPS 180-4: the constants of section 4.2.2, the initial hash value of section 5.3.3, the padding of section 5.1.1 and the computation of section 6.2.2.

SPDX-License-Identifier: MIT

Function Documentation

◆ compress()

void compress ( uint32_t h[8],
const uint8_t block[64] )
static

One 512-bit block (section 6.2.2, steps 1 to 4).

Parameters
hThe eight 32-bit hash words, updated in place.
blockThe 64 bytes of the block.

◆ link_sha256()

void link_sha256 ( const void * data,
size_t len,
uint8_t out[LINK_SHA256_BYTES] )

The digest of len bytes in one call.

Parameters
dataThe bytes to digest; may be NULL when len is 0.
lenNumber of bytes in data.
outReceives the 32-byte digest.

◆ link_sha256_final()

void link_sha256_final ( link_sha256_t * s,
uint8_t out[LINK_SHA256_BYTES] )

Pad, finish and write the 32-byte digest. s is spent afterwards.

Parameters
sThe state, from link_sha256_init() and link_sha256_update().
outReceives the 32-byte digest.

◆ link_sha256_init()

void link_sha256_init ( link_sha256_t * s)

Start a computation: set the initial hash value and clear the state.

Parameters
sThe state to set up. NULL does nothing.

◆ link_sha256_update()

void link_sha256_update ( link_sha256_t * s,
const void * data,
size_t len )

Fold len bytes in. data may be NULL when len is 0.

Parameters
sThe state, from link_sha256_init().
dataThe bytes to fold in; may be NULL when len is 0.
lenNumber of bytes in data.

◆ rotr()

uint32_t rotr ( uint32_t x,
unsigned n )
static

Rotate a 32-bit word right.

Parameters
xThe word to rotate.
nBit count; the callers pass 2 to 25.
Returns
The rotated word.

Variable Documentation

◆ k_round

const uint32_t k_round[64]
static
Initial value:
= {
0x428a2f98u, 0x71374491u, 0xb5c0fbcfu, 0xe9b5dba5u,
0x3956c25bu, 0x59f111f1u, 0x923f82a4u, 0xab1c5ed5u,
0xd807aa98u, 0x12835b01u, 0x243185beu, 0x550c7dc3u,
0x72be5d74u, 0x80deb1feu, 0x9bdc06a7u, 0xc19bf174u,
0xe49b69c1u, 0xefbe4786u, 0x0fc19dc6u, 0x240ca1ccu,
0x2de92c6fu, 0x4a7484aau, 0x5cb0a9dcu, 0x76f988dau,
0x983e5152u, 0xa831c66du, 0xb00327c8u, 0xbf597fc7u,
0xc6e00bf3u, 0xd5a79147u, 0x06ca6351u, 0x14292967u,
0x27b70a85u, 0x2e1b2138u, 0x4d2c6dfcu, 0x53380d13u,
0x650a7354u, 0x766a0abbu, 0x81c2c92eu, 0x92722c85u,
0xa2bfe8a1u, 0xa81a664bu, 0xc24b8b70u, 0xc76c51a3u,
0xd192e819u, 0xd6990624u, 0xf40e3585u, 0x106aa070u,
0x19a4c116u, 0x1e376c08u, 0x2748774cu, 0x34b0bcb5u,
0x391c0cb3u, 0x4ed8aa4au, 0x5b9cca4fu, 0x682e6ff3u,
0x748f82eeu, 0x78a5636fu, 0x84c87814u, 0x8cc70208u,
0x90befffau, 0xa4506cebu, 0xbef9a3f7u, 0xc67178f2u,
}

The first 32 bits of the fractional parts of the cube roots of the first 64 primes (section 4.2.2).