MentOS  0.8.0
The Mentoring Operating System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Classes | Macros | Functions
sha256.h File Reference

Implementation of the SHA-256 hashing algorithm. More...

Go to the source code of this file.

Classes

struct  SHA256_ctx_t
 Structure that holds context information for SHA-256 operations. More...
 

Macros

#define SHA256_BLOCK_SIZE   32
 SHA256 outputs a 32 byte digest.
 

Functions

void sha256_init (SHA256_ctx_t *ctx)
 Initializes the SHA-256 context. More...
 
void sha256_update (SHA256_ctx_t *ctx, const uint8_t data[], size_t len)
 Adds data to the SHA-256 context for hashing. More...
 
void sha256_final (SHA256_ctx_t *ctx, uint8_t hash[])
 Finalizes the hashing and produces the final SHA-256 digest. More...
 
void sha256_bytes_to_hex (uint8_t *src, size_t src_length, char *out, size_t out_length)
 Converts a byte array to its hexadecimal string representation. More...
 

Detailed Description

Implementation of the SHA-256 hashing algorithm.

The original code was written by Brad Conte, and is available at: https://github.com/B-Con/crypto-algorithms

SHA-256 is one of the three algorithms in the SHA2 specification. The others, SHA-384 and SHA-512, are not offered in this implementation. Algorithm specification can be found here: http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf This implementation uses little endian byte order.

Function Documentation

◆ sha256_bytes_to_hex()

void sha256_bytes_to_hex ( uint8_t src,
size_t  src_length,
char *  out,
size_t  out_length 
)

Converts a byte array to its hexadecimal string representation.

Parameters
srcPointer to the source byte array.
src_lengthLength of the source byte array.
outPointer to the output buffer for the hexadecimal string.
out_lengthLength of the output buffer (must be at least 2 * src_length + 1).

The output string will be null-terminated if the buffer is large enough.

Converts a byte array to its hexadecimal string representation.

Parameters
srcPointer to the source byte array.
src_lengthLength of the source byte array.
outPointer to the output buffer for the hexadecimal string.
out_lengthLength of the output buffer (must be at least 2 * src_length + 1).

The output string will be null-terminated if the buffer is large enough.

◆ sha256_final()

void sha256_final ( SHA256_ctx_t ctx,
uint8_t  hash[] 
)

Finalizes the hashing and produces the final SHA-256 digest.

Parameters
ctxPointer to the SHA-256 context.
hashPointer to a buffer where the final hash will be stored (must be at least 32 bytes long).

◆ sha256_init()

void sha256_init ( SHA256_ctx_t ctx)

Initializes the SHA-256 context.

Parameters
ctxPointer to the SHA-256 context to initialize.

◆ sha256_update()

void sha256_update ( SHA256_ctx_t ctx,
const uint8_t  data[],
size_t  len 
)

Adds data to the SHA-256 context for hashing.

Parameters
ctxPointer to the SHA-256 context.
dataPointer to the data to be hashed.
lenLength of the data to hash, in bytes.