Extended Library Functions sha2(3EXT)
NAME
sha2, SHA2Init, SHA2Update, SHA2Final, SHA256Init,
SHA256Update, SHA256Final, SHA384Init, SHA384Update,
SHA384Final, SHA512Init, SHA512Update, SHA512Final - SHA2
digest functions
SYNOPSIS
cc [ flag ... ] file ... -lmd [ library ... ]
#include
void SHA2Init(uint64t mech, SHA2CTX *context);
void SHA2Update(SHA2CTX *context, unsigned char *input,
unsigned int inlen);
void SHA2Final(unsigned char *output, SHA2CTX *context);
void SHA256Init(SHA256CTX *context);
void SHA256Update(SHA256CTX *context, unsigned char *input,
unsigned int inlen);
void SHA256Final(unsigned char *output, SHA256CTX *context);
void SHA384Init(SHA384CTX *context);
void SHA384Update(SHA384CTX *context, unsigned char *input,
unsigned int inlen);
void SHA384Final(unsigned char *output, 384CTX *context);
void SHA512Init(SHA512CTX *context);
void SHA512Update(SHA512CTX *context, unsigned char *input,
unsigned int inlen);
void SHA512Final(unsigned char *output, 512CTX *context);
DESCRIPTION
SunOS 5.11 Last change: 13 Nov 2007 1
Extended Library Functions sha2(3EXT)
The SHA2Init(), SHA2Update(), SHA2Final() functions imple-
ment the SHA256, SHA384 and SHA512 message-digest algo-
rithms. The algorithms take as input a message of arbitrary
length and produces a 200-bit "fingerprint" or "message dig-
est" as output. The SHA2 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.
SHA2Init(), SHA2Update(), SHA2Final()
The SHA2Init(), SHA2Update(), and SHA2Final() functions
allow an SHA2 digest to be computed over multiple mes-
sage blocks. Between blocks, the state of the SHA2 com-
putation is held in an SHA2 context structure allocated
by the caller. A complete digest computation consists of
calls to SHA2 functions in the following order: one call
to SHA2Init(), one or more calls to SHA2Update(), and
one call to SHA2Final().
The SHA2Init() function initializes the SHA2 context
structure pointed to by context. The mech argument is
one of SHA256, SHA512, SHA384.
The SHA2Update() function computes a partial SHA2 digest
on the inlen-byte message block pointed to by input, and
updates the SHA2 context structure pointed to by context
accordingly.
The SHA2Final() function generates the final SHA2Final
digest, using the SHA2 context structure pointed to by
context. The SHA2 digest is written to output. After a
call to SHA2Final(), the state of the context structure
is undefined. It must be reinitialized with SHA2Init()
before it can be used again.
SHA256Init(), SHA256Update(), SHA256Final(), SHA384Init(),
SHA384Update(), SHA384Final(), SHA512Init(), SHA512Update(),
SHA512Final()
Alternative APIs exist as named above. The Update() and
Final() sets of functions operate exactly as the previ-
ously described SHA2Update() and SHA2Final() functions.
The SHA256Init(), SHA384Init(), and SHA512Init() func-
tions do not take the mech argument as it is implicit in
the function names.
RETURN VALUES
SunOS 5.11 Last change: 13 Nov 2007 2
Extended Library Functions sha2(3EXT)
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 mes-
sage found in multiple buffers. The calling function pro-
vides an authentication buffer to contain the result of the
SHA2 digest.
#include
#include
#include
int
AuthenticateMsg(unsigned char *authbuffer, struct iovec
*messageIov, unsigned int numbuffers)
{
SHA2CTX sha2context;
unsigned int i;
SHA2Init(SHA384, &sha2context);
for(i=0; iiovbase,
messageIov->iovlen);
messageIov ]= sizeof(struct iovec);
}
SHA2Final(authbuffer, &sha2context);
return 0;
}
Example 2 Authenticate a message found in multiple buffers
The following is a sample function that authenticates a mes-
sage found in multiple buffers. The calling function pro-
vides an authentication buffer that will contain the result
of the SHA384 digest, using alternative interfaces.
int
AuthenticateMsg(unsigned char *authbuffer, struct iovec
*messageIov, unsigned int numbuffers)
{
SHA384CTX ctx;
SunOS 5.11 Last change: 13 Nov 2007 3
Extended Library Functions sha2(3EXT)
unsigned int i;
SHA384Init(&ctx);
for(i=0, iiovbase,
messageIov->iovlen);
messageIov ]= sizeof(struct iovec);
}
SHA384Final(authbuffer, &ctx);
return 0;
}
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
Interface Stability Committed
MT-Level MT-Safe
SEE ALSO
libmd(3LIB)
FIPS 180-2
SunOS 5.11 Last change: 13 Nov 2007 4
|