Contained WithinFind More DocumentationFeatured Support Resources | PDF로 이 문서 다운로드 (4971 KB)
sha2(3EXT)Name | Synopsis | Description | Return Values | Examples | Attributes | See Also Name
Synopsiscc [ flag ... ] file ... -lmd [ library ... ] #include <sha2.h> void SHA2Init(uint64_t mech, SHA2_CTX *context);
void SHA2Update(SHA2_CTX *context, unsigned char *input,
unsigned int inlen);
void SHA2Final(unsigned char *output, SHA2_CTX *context); void SHA256Init(SHA256_CTX *context);
void SHA256Update(SHA256_CTX *context, unsigned char *input,
unsigned int inlen);
void SHA256Final(unsigned char *output, SHA256_CTX *context); void SHA384Init(SHA384_CTX *context);
void SHA384Update(SHA384_CTX *context, unsigned char *input,
unsigned int inlen);
void SHA384Final(unsigned char *output, 384_CTX *context); void SHA512Init(SHA512_CTX *context);
void SHA512Update(SHA512_CTX *context, unsigned char *input,
unsigned int inlen);
void SHA512Final(unsigned char *output, 512_CTX *context); Description
The SHA2Init(), SHA2Update(), SHA2Final() functions implement the SHA256, SHA384 and SHA512 message-digest algorithms. The algorithms take as input a message of arbitrary length and produces a 200-bit “fingerprint” or “message digest” 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. Return ValuesThese functions do not return a value. ExamplesExample 1 Authenticate a message found in multiple buffersThe 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 SHA2 digest. #include <sys/types.h>
#include <sys/uio.h>
#include <sha2.h>
int
AuthenticateMsg(unsigned char *auth_buffer, struct iovec
*messageIov, unsigned int num_buffers)
{
SHA2_CTX sha2_context;
unsigned int i;
SHA2Init(SHA384, &sha2_context);
for(i=0; i<num_buffers; i++)
{
SHA2Update(&sha2_context, messageIov->iov_base,
messageIov->iov_len);
messageIov += sizeof(struct iovec);
}
SHA2Final(auth_buffer, &sha2_context);
return 0;
}
Example 2 Authenticate a message found in multiple buffersThe following is a sample function that authenticates a message found in multiple buffers. The calling function provides an authentication buffer that will contain the result of the SHA384 digest, using alternative interfaces. int
AuthenticateMsg(unsigned char *auth_buffer, struct iovec
*messageIov, unsigned int num_buffers)
{
SHA384_CTX ctx;
unsigned int i;
SHA384Init(&ctx);
for(i=0, i<num_buffers; i++
{
SHA384Update(&ctx, messageIov->iov_base,
messageIov->iov_len);
messageIov += sizeof(struct iovec);
}
SHA384Final(auth_buffer, &ctx);
return 0;
}
AttributesSee attributes(5) for descriptions of the following attributes:
See AlsoFIPS 180–2 Name | Synopsis | Description | Return Values | Examples | Attributes | See Also |
||||||