Go to main content

man pages section 3: Extended Library Functions, Volume 1

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

SHA3Final(3EXT)

Name

sha3, SHA3Init, SHA3Update, SHA3Final - the SHA-3 family of digest functions

Synopsis

cc [ flag ... ] file ... -lmd [ library ... ]
#include <sha3.h>

void SHA3Init(uint64_t mech, SHA3_CTX *context);

void SHA3Update(SHA3_CTX *context, const void *input,
     size_t inlen);

void SHA3Final(void *output, SHA3_CTX *context);

Description

The SHA3Init(), SHA3Update(), and SHA3Final() functions implement the SHA-3 family of message-digest algorithms. The algorithms take as input a message of arbitrary length and produce a fingerprint or message digest as output. The SHA message-digest algorithms are intended for digital signature applications in which large files are compressed in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA.

SHA3Init(), SHA3Update(), and SHA3Final()

The SHA3Init(), SHA3Update(), and SHA3Final() functions allow an SHA3 digest to be computed over multiple message blocks. Between blocks, the state of the SHA3 computation is held in an SHA3 context structure allocated by the caller. A complete digest computation consists of calls to SHA3 functions in the following order:

  • One call to the SHA3Init() function

  • One or more calls to the SHA3Update() function

  • One call to the SHA3Final() function

The SHA3Init() function initializes the SHA3_CTX context structure pointed to by context. The mech argument is one of SHA3_224, SHA3_256, SHA3_384, or SHA3_512.

The SHA3Update() function computes a partial SHA-3 digest on the inlen-byte message block pointed to by input, and updates the SHA3_CTX context structure pointed to by context accordingly.

The SHA3Final() function generates the final SHA-3 digest, using the SHA3_CTX context structure pointed to by context. The SHA3 digest is written to output. After a call to the SHA3Final() function, the state of the context structure is undefined. It must be reinitialized with the SHA3Init() function before it can be used again.

Return Values

These functions do not return a value.

Examples

Example 1 Authenticate a message found in multiple buffers

The following is a sample function that authenticates a message found in multiple buffers. The calling function provides an authentication buffer to contain the result of the SHA-3 digest.

#include <sys/types.h>
#include <sys/uio.h>
#include <sha3.h>

int
AuthenticateMsg(unsigned char *auth_buffer, struct iovec
                *messageIov, unsigned int num_buffers)
{
    SHA3_CTX sha3_context;
    unsigned int i;

    SHA3Init(SHA3_384, &sha3_context);

    for(i = 0; i < num_buffers; i++)
    {
         SHA3Update(&sha3_context, messageIov->iov_base,
                   messageIov->iov_len);
         messageIov += sizeof(struct iovec);
    }

    SHA3Final(auth_buffer, &sha3_context);

    return 0;
}

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe

See Also

libmd(3LIB)

FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions

https://csrc.nist.gov/publications/detail/fips/202/final

History

These functions were added to Oracle Solaris in Solaris 11.4.0.