SHA
[Hash]

Defines

#define C4E_SHA1_DIGEST_LEN
#define C4E_SHA1_BLOCK_LEN
#define C4E_SHA1_CTX_WORDS
#define C4E_SHA1_TMP_WORDS
#define C4E_SHA1_MEM_WORDS
#define C4E_SHA224_DIGEST_LEN
#define C4E_SHA256_DIGEST_LEN
#define C4E_SHA2_BLOCK_LEN
#define C4E_SHA2_CTX_WORDS
#define C4E_SHA2_TMP_WORDS
#define C4E_SHA2_MEM_WORDS

Functions

void c4e_sha1_start (C4eAlgo32Uint ctx[C4E_SHA1_CTX_WORDS])
 Start of SHA-1.
void c4e_sha1_next (C4eAlgo32Uint ctx[C4E_RESTRICT C4E_SHA1_CTX_WORDS], C4eAlgo32Uint wtmp[C4E_RESTRICT C4E_SHA1_TMP_WORDS], C4E_CONST void *C4E_RESTRICT next)
 Processes the next data block of 64 bytes (C4E_SHA1_BLOCK_LEN) with SHA-1.
void c4e_sha1_stop (C4eAlgo32Uint ctx[C4E_RESTRICT C4E_SHA1_CTX_WORDS], C4eAlgo32Uint wtmp[C4E_RESTRICT C4E_SHA1_TMP_WORDS], C4E_CONST void *C4E_RESTRICT last, C4eArchUint len, C4eArchUint8 digest[C4E_RESTRICT C4E_SHA1_DIGEST_LEN])
 Processes the last SHA-1 data block (possibly of length zero) and returns the SHA-1 digest.
void c4e_sha1_mem (C4eAlgo32Uint tmp[C4E_RESTRICT C4E_SHA1_MEM_WORDS], C4E_CONST void *C4E_RESTRICT mem, C4eArchSize len, C4eArchUint8 digest[C4E_RESTRICT C4E_SHA1_DIGEST_LEN])
 This is an all-in-one function for the sandwich c4e_sha1_start(), c4e_sha1_next() and c4e_sha1_stop(), which computes the SHA-1 digest over a memory area.
void c4e_sha2_start (C4eAlgo32Uint ctx[C4E_SHA2_CTX_WORDS], C4eHashId hid)
 Start of SHA-224 or SHA-256.
void c4e_sha2_next (C4eAlgo32Uint ctx[C4E_RESTRICT C4E_SHA2_CTX_WORDS], C4eAlgo32Uint wtmp[C4E_RESTRICT C4E_SHA2_TMP_WORDS], C4E_CONST void *C4E_RESTRICT next)
 Processes the next data block of 64 bytes (C4E_SHA2_BLOCK_LEN) with SHA-256 or SHA224.
void c4e_sha2_stop (C4eAlgo32Uint ctx[C4E_RESTRICT C4E_SHA2_CTX_WORDS], C4eAlgo32Uint wtmp[C4E_RESTRICT C4E_SHA2_TMP_WORDS], C4E_CONST void *C4E_RESTRICT last, C4eArchUint len, C4eArchUint8 digest[C4E_RESTRICT C4E_SHA256_DIGEST_LEN])
 Processes the last SHA-224 or SHA-256 data block (possibly of length zero) and returns the digest.
void c4e_sha2_mem (C4eAlgo32Uint tmp[C4E_RESTRICT C4E_SHA2_MEM_WORDS], C4eHashId hid, C4E_CONST void *C4E_RESTRICT mem, C4eArchSize len, C4eArchUint8 digest[C4E_RESTRICT C4E_SHA256_DIGEST_LEN])
 This is an all-in-one function for the sandwich c4e_sha2_start(), c4e_sha2_next() and c4e_sha2_stop(), which computes the SHA-256/224 digest over a memory area.

Define Documentation

#define C4E_SHA1_DIGEST_LEN

Digest length of SHA-1 in bytes.

Definition at line 47 of file c4e_sha.h.

#define C4E_SHA1_BLOCK_LEN

Block length of SHA-1 in bytes (64)

Definition at line 52 of file c4e_sha.h.

#define C4E_SHA1_CTX_WORDS

Number of C4eAlgo32Uint context words to be passed to SHA-1 routines.

Definition at line 57 of file c4e_sha.h.

#define C4E_SHA1_TMP_WORDS

Number of C4eAlgo32Uint words to be used for temporary space in SHA-1 routines.

Definition at line 63 of file c4e_sha.h.

#define C4E_SHA1_MEM_WORDS

Number of C4eAlgo32Uint words needed by c4e_sha1_mem().

Definition at line 68 of file c4e_sha.h.

#define C4E_SHA224_DIGEST_LEN

Digest length of SHA-224 in bytes

Definition at line 73 of file c4e_sha.h.

#define C4E_SHA256_DIGEST_LEN

Digest length of SHA-256 in bytes

Definition at line 74 of file c4e_sha.h.

#define C4E_SHA2_BLOCK_LEN

Block length of SHA-256/224 in bytes (64)

Definition at line 80 of file c4e_sha.h.

#define C4E_SHA2_CTX_WORDS

Number of C4eAlgo32Uint context words to be passed to SHA-2 routines.

Definition at line 85 of file c4e_sha.h.

#define C4E_SHA2_TMP_WORDS

Number of C4eAlgo32Uint words to be used for temporary space in SHA-2 routines.

Definition at line 91 of file c4e_sha.h.

#define C4E_SHA2_MEM_WORDS

Number of C4eAlgo32Uint words needed by c4e_sha2_mem().

Definition at line 96 of file c4e_sha.h.


Function Documentation

void c4e_sha1_start ( C4eAlgo32Uint  ctx[C4E_SHA1_CTX_WORDS]  ) 

Start of SHA-1.

Note:
The contents of ctx is transparent to the user, except the memory space to be provided.
Precondition:
ctx must point to pre-allocated memory space of at least C4E_SHA1_CTX_WORDS elements, each of C4eAlgo32Uint size.
Bibliography:
Secure Hash Standard. FIPS Publication 180-1, National Institute of Standards and Technology, 1993.
Bibliography:
Public Key Cryptography Using Irreversible Algorithms - Part 2: The Secure Hash Algorithm (SHA-1). ANSI X9.30-2, 1997.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
[out] ctx A working context with memory space provided by the user. The returned context from this function must be passed to c4e_sha1_next() and c4e_sha1_stop().
See also:
c4e_sha1_next(), c4e_sha1_stop()
void c4e_sha1_next ( C4eAlgo32Uint  ctx[C4E_RESTRICT C4E_SHA1_CTX_WORDS],
C4eAlgo32Uint  wtmp[C4E_RESTRICT C4E_SHA1_TMP_WORDS],
C4E_CONST void *C4E_RESTRICT  next 
)

Processes the next data block of 64 bytes (C4E_SHA1_BLOCK_LEN) with SHA-1.

Note:
Call c4e_sha1_stop() for the last block (which possibly has a length less than C4E_SHA1_BLOCK_LEN).
Precondition:
Call of c4e_sha1_start(), then passing ctx here.
The maximum number of data blocks (each of length C4E_SHA1_BLOCK_LEN), which can be processed by this implementation of SHA-1, is limited to 2^32 - 1. The user has to ensure that this function is not called more often than this limit (certainly inside the sandwich of c4e_sha1_start() and c4e_sha1_stop()).
Bibliography:
Secure Hash Standard. FIPS Publication 180-1, National Institute of Standards and Technology, 1993.
Bibliography:
Public Key Cryptography Using Irreversible Algorithms - Part 2: The Secure Hash Algorithm (SHA-1). ANSI X9.30-2, 1997.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
[in,out] ctx Context as prepared by function c4e_sha1_start(), which must be persistent between successive calls.
wtmp Temporary space used for processing of array w[] and backup of H values (must not be persistent between successive calls).
[in] next The next data block (of C4E_SHA1_BLOCK_LEN bytes) to be processed.
See also:
c4e_sha1_start(), c4e_sha1_stop()
void c4e_sha1_stop ( C4eAlgo32Uint  ctx[C4E_RESTRICT C4E_SHA1_CTX_WORDS],
C4eAlgo32Uint  wtmp[C4E_RESTRICT C4E_SHA1_TMP_WORDS],
C4E_CONST void *C4E_RESTRICT  last,
C4eArchUint  len,
C4eArchUint8  digest[C4E_RESTRICT C4E_SHA1_DIGEST_LEN] 
)

Processes the last SHA-1 data block (possibly of length zero) and returns the SHA-1 digest.

Precondition:
Call of c4e_sha1_start() and possibly c4e_sha1_next() multiple times, then passing ctx here.
Bibliography:
Secure Hash Standard. FIPS Publication 180-1, National Institute of Standards and Technology, 1993.
Bibliography:
Public Key Cryptography Using Irreversible Algorithms - Part 2: The Secure Hash Algorithm (SHA-1). ANSI X9.30-2, 1997.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
[in] ctx Context as passed to c4e_sha1_start() and c4e_sha1_next(), which must be persistent between function calls.
wtmp Temporary space used for processing of array w[] and backup of H values (must not be persistent with respect to c4e_sha1_next()).
[in] last The last data block to be processed.
[in] len Length of last block (0...C4E_SHA1_BLOCK_LEN bytes)
[out] digest Pointer to buffer which gets the SHA-1 message digest. Notice that this pointer is allowed to alias wtmp.
See also:
c4e_sha1_start(), c4e_sha1_next()
void c4e_sha1_mem ( C4eAlgo32Uint  tmp[C4E_RESTRICT C4E_SHA1_MEM_WORDS],
C4E_CONST void *C4E_RESTRICT  mem,
C4eArchSize  len,
C4eArchUint8  digest[C4E_RESTRICT C4E_SHA1_DIGEST_LEN] 
)

This is an all-in-one function for the sandwich c4e_sha1_start(), c4e_sha1_next() and c4e_sha1_stop(), which computes the SHA-1 digest over a memory area.

Precondition:
The maximum number of bytes which can be processed by this implementation of SHA-1 is limited to (2^32 - 1) * C4E_SHA1_BLOCK_LEN. The user has to ensure that len is less than this limit (including an extra block inserted for padding).
Bibliography:
Secure Hash Standard. FIPS Publication 180-1, National Institute of Standards and Technology, 1993.
Bibliography:
Public Key Cryptography Using Irreversible Algorithms - Part 2: The Secure Hash Algorithm (SHA-1). ANSI X9.30-2, 1997.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
tmp Temporary used memory space, provided by the caller.
[in] mem Pointer to start of memory area, for which a SHA-1 digest is calculated. If len is zero, then it is allowed to set mem NULL.
[in] len Length of memory area in bytes.
[out] digest Pointer to buffer which gets the SHA-1 message digest. Notice that this pointer is allowed to alias tmp.
void c4e_sha2_start ( C4eAlgo32Uint  ctx[C4E_SHA2_CTX_WORDS],
C4eHashId  hid 
)

Start of SHA-224 or SHA-256.

Note:
The contents of ctx is transparent to the user, except the memory space to be provided.
Precondition:
ctx must point to pre-allocated memory space of at least C4E_SHA2_CTX_WORDS elements, each of C4eAlgo32Uint size.
Bibliography:
Secure Hash Standard (SHS). FIPS Publication 180-3, National Institute of Standards and Technology, 2008.
Bibliography:
Public Key Cryptography Using Irreversible Algorithms - Part 2: The Secure Hash Algorithm (SHA-1). ANSI X9.30-2, 1997.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
[out] ctx A working context with memory space provided by the user. The returned context from this function must be passed to c4e_sha2_next() and c4e_sha2_stop().
[in] hid Hash algorithm identifier, which must be C4eHashId::C4eHashIdSha224 or C4eHashId::C4eHashIdSha256.
See also:
c4e_sha2_next(), c4e_sha2_stop()
void c4e_sha2_next ( C4eAlgo32Uint  ctx[C4E_RESTRICT C4E_SHA2_CTX_WORDS],
C4eAlgo32Uint  wtmp[C4E_RESTRICT C4E_SHA2_TMP_WORDS],
C4E_CONST void *C4E_RESTRICT  next 
)

Processes the next data block of 64 bytes (C4E_SHA2_BLOCK_LEN) with SHA-256 or SHA224.

Note:
Call c4e_sha2_stop() for the last block (which possibly has a length less than C4E_SHA2_BLOCK_LEN).
Precondition:
Call of c4e_sha2_start(), then passing ctx here.
The maximum number of data blocks (each of length C4E_SHA2_BLOCK_LEN), which can be processed by this implementation of SHA-256/224, is limited to 2^32 - 1. The user has to ensure that this function is not called more often than this limit (certainly inside the sandwich of c4e_sha2_start() and c4e_sha2_stop()).
Bibliography:
Secure Hash Standard (SHS). FIPS Publication 180-3, National Institute of Standards and Technology, 2008.
Bibliography:
Public Key Cryptography Using Irreversible Algorithms - Part 2: The Secure Hash Algorithm (SHA-1). ANSI X9.30-2, 1997.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
[in,out] ctx Context as prepared by function c4e_sha2_start(), which must be persistent between successive calls.
wtmp Temporary space used for processing of array w[] and backup of H values (must not be persistent between successive calls).
[in] next The next data block (of C4E_SHA2_BLOCK_LEN bytes) to be processed.
See also:
c4e_sha2_start(), c4e_sha2_stop()
void c4e_sha2_stop ( C4eAlgo32Uint  ctx[C4E_RESTRICT C4E_SHA2_CTX_WORDS],
C4eAlgo32Uint  wtmp[C4E_RESTRICT C4E_SHA2_TMP_WORDS],
C4E_CONST void *C4E_RESTRICT  last,
C4eArchUint  len,
C4eArchUint8  digest[C4E_RESTRICT C4E_SHA256_DIGEST_LEN] 
)

Processes the last SHA-224 or SHA-256 data block (possibly of length zero) and returns the digest.

Precondition:
Call of c4e_sha2_start() and possibly c4e_sha2_next() multiple times, then passing ctx here.
Bibliography:
Secure Hash Standard (SHS). FIPS Publication 180-3, National Institute of Standards and Technology, 2008.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
[in] ctx Context as passed to c4e_sha2_start() and c4e_sha2_next(), which must be persistent between function calls.
wtmp Temporary space used for processing of array w[] and backup of H values (must not be persistent with respect to c4e_sha2_next()).
[in] last The last data block to be processed.
[in] len Length of last block (0...C4E_SHA2_BLOCK_LEN bytes)
[out] digest Pointer to buffer which gets the SHA-224/256 message digest (for SHA-224 only the first C4E_SHA224_DIGEST_LEN bytes are valid). Notice that this pointer is allowed to alias wtmp.
See also:
c4e_sha2_start(), c4e_sha2_next()
void c4e_sha2_mem ( C4eAlgo32Uint  tmp[C4E_RESTRICT C4E_SHA2_MEM_WORDS],
C4eHashId  hid,
C4E_CONST void *C4E_RESTRICT  mem,
C4eArchSize  len,
C4eArchUint8  digest[C4E_RESTRICT C4E_SHA256_DIGEST_LEN] 
)

This is an all-in-one function for the sandwich c4e_sha2_start(), c4e_sha2_next() and c4e_sha2_stop(), which computes the SHA-256/224 digest over a memory area.

Precondition:
The maximum number of bytes which can be processed by this implementation of SHA-256/224 is limited to (2^32 - 1) * C4E_SHA2_BLOCK_LEN. The user has to ensure that len is less than this limit (including an extra block inserted for padding).
Bibliography:
Secure Hash Standard (SHS). FIPS Publication 180-3, National Institute of Standards and Technology, 2008.
Bibliography:
Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions. ISO 10118-3, 2004.
Parameters:
tmp Temporary used memory space, provided by the caller.
[in] hid Hash algorithm identifier, which must be C4eHashId::C4eHashIdSha224 or C4eHashId::C4eHashIdSha256.
[in] mem Pointer to start of memory area, for which a SHA-256 or SHA-224 digest shall be calculated. If len is zero, then it is allowed to set mem NULL.
[in] len Length of memory area in bytes.
[out] digest Pointer to buffer which gets the SHA-224/256 message digest (for SHA-224 only the first C4E_SHA224_DIGEST_LEN bytes are valid). Notice that this pointer is allowed to alias tmp.