sha256.c

April 3, 2026 ยท View on GitHub

Purpose

SHA-256 stateful and one-shot helpers.

API Reference

void XSHA256_Init(xsha256_t *pSha)

  • Arguments:
    • pSha: destination SHA-256 context.
  • Does:
    • initializes digest state, block buffer and counters.
  • Returns:
    • no return value.

void XSHA256_ProcessBlock(xsha256_t *pSha)

  • Arguments:
    • initialized SHA-256 context whose block is ready.
  • Does:
    • processes one 64-byte compression block.
  • Returns:
    • no return value.

void XSHA256_Update(xsha256_t *pSha, const uint8_t *pData, size_t nLength)

  • Arguments:
    • context plus input bytes and length.
  • Does:
    • appends bytes into running SHA-256 state.
  • Returns:
    • no return value.

void XSHA256_Final(xsha256_t *pSha, uint8_t *pDigest)

  • Arguments:
    • context and 32-byte destination buffer.
  • Does:
    • pads, finalizes and writes raw digest.
  • Returns:
    • no return value.

void XSHA256_FinalRaw(xsha256_t *pSha, uint8_t *pDigest)

  • Arguments:
    • context and 32-byte destination buffer.
  • Does:
    • copies current internal digest words without full final padding path.
  • Returns:
    • no return value.

XSTATUS XSHA256_Compute(uint8_t *pOutput, size_t nSize, const uint8_t *pInput, size_t nLength)

  • Does:
    • one-shot raw SHA-256 digest.
  • Returns:
    • XSTDOK on success.
    • failure status for invalid output buffer or internal error.

XSTATUS XSHA256_ComputeSum(char *pOutput, size_t nSize, const uint8_t *pInput, size_t nLength)

  • Does:
    • one-shot lowercase hex SHA-256.
  • Returns:
    • XSTDOK or failure status.

uint8_t *XSHA256_Encrypt(const uint8_t *pInput, size_t nLength)

  • Returns:
    • allocated raw 32 + 1 digest buffer or NULL.

char *XSHA256_Sum(const uint8_t *pInput, size_t nLength)

  • Returns:
    • allocated lowercase hex string or NULL.