2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SHA2 3EXT "Nov 13, 2007"
8 sha2, SHA2Init, SHA2Update, SHA2Final, SHA256Init, SHA256Update, SHA256Final,
9 SHA384Init, SHA384Update, SHA384Final, SHA512Init, SHA512Update, SHA512Final \-
14 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lmd\fR [ \fIlibrary\fR ... ]
17 \fBvoid\fR \fBSHA2Init\fR(\fBuint64_t\fR \fImech\fR, \fBSHA2_CTX *\fR\fIcontext\fR);
22 \fBvoid\fR \fBSHA2Update\fR(\fBSHA2_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
23 \fBunsigned int\fR \fIinlen\fR);
28 \fBvoid\fR \fBSHA2Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fBSHA2_CTX *\fR\fIcontext\fR);
33 \fBvoid\fR \fBSHA256Init\fR(\fBSHA256_CTX *\fR\fIcontext\fR);
38 \fBvoid\fR \fBSHA256Update\fR(\fBSHA256_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
39 \fBunsigned int\fR \fIinlen\fR);
44 \fBvoid\fR \fBSHA256Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fBSHA256_CTX *\fR\fIcontext\fR);
49 \fBvoid\fR \fBSHA384Init\fR(\fBSHA384_CTX *\fR\fIcontext\fR);
54 \fBvoid\fR \fBSHA384Update\fR(\fBSHA384_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
55 \fBunsigned int\fR \fIinlen\fR);
60 \fBvoid\fR \fBSHA384Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fB384_CTX *\fR\fIcontext\fR);
65 \fBvoid\fR \fBSHA512Init\fR(\fBSHA512_CTX *\fR\fIcontext\fR);
70 \fBvoid\fR \fBSHA512Update\fR(\fBSHA512_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
71 \fBunsigned int\fR \fIinlen\fR);
76 \fBvoid\fR \fBSHA512Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fB512_CTX *\fR\fIcontext\fR);
82 The \fBSHA2Init()\fR, \fBSHA2Update()\fR, \fBSHA2Final()\fR functions implement
83 the \fBSHA256\fR, \fBSHA384\fR and \fBSHA512\fR message-digest algorithms. The
84 algorithms take as input a message of arbitrary length and produces a 200-bit
85 "fingerprint" or "message digest" as output. The \fBSHA2\fR message-digest
86 algorithms are intended for digital signature applications in which large files
87 are "compressed" in a secure manner before being encrypted with a private
88 (secret) key under a public-key cryptosystem such as RSA.
92 \fB\fBSHA2Init()\fR, \fBSHA2Update()\fR, \fBSHA2Final()\fR\fR
96 The \fBSHA2Init()\fR, \fBSHA2Update()\fR, and \fBSHA2Final()\fR functions allow
97 an \fBSHA2\fR digest to be computed over multiple message blocks. Between
98 blocks, the state of the \fBSHA2\fR computation is held in an \fBSHA2\fR
99 context structure allocated by the caller. A complete digest computation
100 consists of calls to \fBSHA2\fR functions in the following order: one call to
101 \fBSHA2Init()\fR, one or more calls to \fBSHA2Update()\fR, and one call to
104 The \fBSHA2Init()\fR function initializes the SHA2 context structure pointed to
105 by \fIcontext\fR. The \fImech\fR argument is one of \fBSHA256\fR, \fBSHA512\fR,
108 The \fBSHA2Update()\fR function computes a partial \fBSHA2\fR digest on the
109 \fIinlen\fR-byte message block pointed to by \fIinput\fR, and updates the
110 \fBSHA2\fR context structure pointed to by \fIcontext\fR accordingly.
112 The \fBSHA2Final()\fR function generates the final \fBSHA2Final\fR digest,
113 using the \fBSHA2\fR context structure pointed to by \fIcontext\fR. The
114 \fBSHA2\fR digest is written to output. After a call to \fBSHA2Final()\fR, the
115 state of the context structure is undefined. It must be reinitialized with
116 \fBSHA2Init()\fR before it can be used again.
122 \fB\fBSHA256Init()\fR, \fBSHA256Update()\fR, \fBSHA256Final()\fR,
123 \fBSHA384Init()\fR, \fBSHA384Update()\fR, \fBSHA384Final()\fR,
124 \fBSHA512Init()\fR, \fBSHA512Update()\fR, \fBSHA512Final()\fR\fR
128 Alternative APIs exist as named above. The \fBUpdate()\fR and \fBFinal()\fR
129 sets of functions operate exactly as the previously described
130 \fBSHA2Update()\fR and \fBSHA2Final()\fR functions. The \fBSHA256Init()\fR,
131 \fBSHA384Init()\fR, and \fBSHA512Init()\fR functions do not take the \fImech\fR
132 argument as it is implicit in the function names.
138 These functions do not return a value.
141 \fBExample 1 \fRAuthenticate a message found in multiple buffers
144 The following is a sample function that authenticates a message found in
145 multiple buffers. The calling function provides an authentication buffer to
146 contain the result of the \fBSHA2\fR digest.
151 #include <sys/types.h>
156 AuthenticateMsg(unsigned char *auth_buffer, struct iovec
157 *messageIov, unsigned int num_buffers)
159 SHA2_CTX sha2_context;
162 SHA2Init(SHA384, &sha2_context);
164 for(i=0; i<num_buffers; i++)
166 SHA2Update(&sha2_context, messageIov->iov_base,
167 messageIov->iov_len);
168 messageIov += sizeof(struct iovec);
171 SHA2Final(auth_buffer, &sha2_context);
179 \fBExample 2 \fRAuthenticate a message found in multiple buffers
182 The following is a sample function that authenticates a message found in
183 multiple buffers. The calling function provides an authentication buffer that
184 will contain the result of the \fBSHA384\fR digest, using alternative
191 AuthenticateMsg(unsigned char *auth_buffer, struct iovec
192 *messageIov, unsigned int num_buffers)
199 for(i=0, i<num_buffers; i++
201 SHA384Update(&ctx, messageIov->iov_base,
202 messageIov->iov_len);
203 messageIov += sizeof(struct iovec);
206 SHA384Final(auth_buffer, &ctx);
216 See \fBattributes\fR(5) for descriptions of the following attributes:
224 ATTRIBUTE TYPE ATTRIBUTE VALUE
226 Interface Stability Committed