libc: remove THIRDPARTYLICENSE/extract-copyright
[unleashed.git] / share / man / man3ext / sha2.3ext
blobf55c95c2efdeab98ff1de46bd5ede34738ab7367
1 '\" te
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"
7 .SH NAME
8 sha2, SHA2Init, SHA2Update, SHA2Final, SHA256Init, SHA256Update, SHA256Final,
9 SHA384Init, SHA384Update, SHA384Final, SHA512Init, SHA512Update, SHA512Final \-
10 SHA2 digest functions
11 .SH SYNOPSIS
12 .LP
13 .nf
14 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lmd\fR [ \fIlibrary\fR ... ]
15 #include <sha2.h>
17 \fBvoid\fR \fBSHA2Init\fR(\fBuint64_t\fR \fImech\fR, \fBSHA2_CTX *\fR\fIcontext\fR);
18 .fi
20 .LP
21 .nf
22 \fBvoid\fR \fBSHA2Update\fR(\fBSHA2_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
23      \fBunsigned int\fR \fIinlen\fR);
24 .fi
26 .LP
27 .nf
28 \fBvoid\fR \fBSHA2Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fBSHA2_CTX *\fR\fIcontext\fR);
29 .fi
31 .LP
32 .nf
33 \fBvoid\fR \fBSHA256Init\fR(\fBSHA256_CTX *\fR\fIcontext\fR);
34 .fi
36 .LP
37 .nf
38 \fBvoid\fR \fBSHA256Update\fR(\fBSHA256_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
39      \fBunsigned int\fR \fIinlen\fR);
40 .fi
42 .LP
43 .nf
44 \fBvoid\fR \fBSHA256Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fBSHA256_CTX *\fR\fIcontext\fR);
45 .fi
47 .LP
48 .nf
49 \fBvoid\fR \fBSHA384Init\fR(\fBSHA384_CTX *\fR\fIcontext\fR);
50 .fi
52 .LP
53 .nf
54 \fBvoid\fR \fBSHA384Update\fR(\fBSHA384_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
55      \fBunsigned int\fR \fIinlen\fR);
56 .fi
58 .LP
59 .nf
60 \fBvoid\fR \fBSHA384Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fB384_CTX *\fR\fIcontext\fR);
61 .fi
63 .LP
64 .nf
65 \fBvoid\fR \fBSHA512Init\fR(\fBSHA512_CTX *\fR\fIcontext\fR);
66 .fi
68 .LP
69 .nf
70 \fBvoid\fR \fBSHA512Update\fR(\fBSHA512_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
71      \fBunsigned int\fR \fIinlen\fR);
72 .fi
74 .LP
75 .nf
76 \fBvoid\fR \fBSHA512Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fB512_CTX *\fR\fIcontext\fR);
77 .fi
79 .SH DESCRIPTION
80 .sp
81 .LP
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.
89 .sp
90 .ne 2
91 .na
92 \fB\fBSHA2Init()\fR, \fBSHA2Update()\fR, \fBSHA2Final()\fR\fR
93 .ad
94 .sp .6
95 .RS 4n
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
102 \fBSHA2Final()\fR.
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,
106 \fBSHA384\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.
120 .ne 2
122 \fB\fBSHA256Init()\fR, \fBSHA256Update()\fR, \fBSHA256Final()\fR,
123 \fBSHA384Init()\fR, \fBSHA384Update()\fR, \fBSHA384Final()\fR,
124 \fBSHA512Init()\fR, \fBSHA512Update()\fR, \fBSHA512Final()\fR\fR
126 .sp .6
127 .RS 4n
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.
135 .SH RETURN VALUES
138 These functions do not return a value.
139 .SH EXAMPLES
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.
149 .in +2
151 #include <sys/types.h>
152 #include <sys/uio.h>
153 #include <sha2.h>
156 AuthenticateMsg(unsigned char *auth_buffer, struct iovec
157                 *messageIov, unsigned int num_buffers)
159     SHA2_CTX sha2_context;
160     unsigned int i;
162     SHA2Init(SHA384, &sha2_context);
164     for(i=0; i<num_buffers; i++)
165     {
166          SHA2Update(&sha2_context, messageIov->iov_base,
167                    messageIov->iov_len);
168          messageIov += sizeof(struct iovec);
169     }
171     SHA2Final(auth_buffer, &sha2_context);
173     return 0;
176 .in -2
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
185 interfaces.
188 .in +2
191 AuthenticateMsg(unsigned char *auth_buffer, struct iovec
192                 *messageIov, unsigned int num_buffers)
194     SHA384_CTX ctx;
195     unsigned int i;
197     SHA384Init(&ctx);
199     for(i=0, i<num_buffers; i++
200     {
201          SHA384Update(&ctx, messageIov->iov_base,
202                    messageIov->iov_len);
203          messageIov += sizeof(struct iovec);
204     }
206     SHA384Final(auth_buffer, &ctx);
208     return 0;
211 .in -2
213 .SH ATTRIBUTES
216 See \fBattributes\fR(5) for descriptions of the following attributes:
221 box;
222 c | c
223 l | l .
224 ATTRIBUTE TYPE  ATTRIBUTE VALUE
226 Interface Stability     Committed
228 MT-Level        MT-Safe
231 .SH SEE ALSO
234 \fBlibmd\fR(3LIB)
237 FIPS 180-2