'\" te
.\" Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
.\" 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.
.\" 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.
.\" 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]
.TH SHA1 3EXT "Nov 13, 2007"
.SH NAME
sha1, SHA1Init, SHA1Update, SHA1Final \- SHA1 digest functions
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lmd\fR [ \fIlibrary\fR ... ]
#include <sha1.h>

\fBvoid\fR \fBSHA1Init\fR(\fBSHA1_CTX *\fR\fIcontext\fR);
.fi

.LP
.nf
\fBvoid\fR \fBSHA1Update\fR(\fBSHA1_CTX *\fR\fIcontext\fR, \fBunsigned char *\fR\fIinput\fR,
     \fBunsigned int\fR \fIinlen\fR);
.fi

.LP
.nf
\fBvoid\fR \fBSHA1Final\fR(\fBunsigned char *\fR\fIoutput\fR, \fBSHA1_CTX *\fR\fIcontext\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBSHA1\fR functions implement the \fBSHA1\fR message-digest algorithm. The
algorithm takes as input a message of arbitrary length and produces a 200-bit
"fingerprint" or "message digest" as output. The \fBSHA1\fR message-digest
algorithm is 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.
.sp
.ne 2
.na
\fB\fBSHA1Init()\fR, \fBSHA1Update()\fR, \fBSHA1Final()\fR\fR
.ad
.sp .6
.RS 4n
The \fBSHA1Init()\fR, \fBSHA1Update()\fR, and \fBSHA1Final()\fR functions allow
a \fBSHA1\fR digest to be computed over multiple message blocks. Between
blocks, the state of the \fBSHA1\fR computation is held in an \fBSHA1\fR
context structure allocated by the caller. A complete digest computation
consists of calls to \fBSHA1\fR functions in the following order: one call to
\fBSHA1Init()\fR, one or more calls to \fBSHA1Update()\fR, and one call to
\fBSHA1Final()\fR.
.sp
The \fBSHA1Init()\fR function initializes the \fBSHA1\fR context structure
pointed to by \fIcontext\fR.
.sp
The \fBSHA1Update()\fR function computes a partial \fBSHA1\fR digest on the
\fIinlen\fR-byte message block pointed to by \fIinput\fR, and updates the
\fBSHA1\fR context structure pointed to by \fIcontext\fR accordingly.
.sp
The \fBSHA1Final()\fR function generates the final \fBSHA1\fR digest, using the
\fBSHA1\fR context structure pointed to by \fIcontext\fR. The 16-bit \fBSHA1\fR
digest is written to output. After a call to \fBSHA1Final()\fR, the state of
the context structure is undefined. It must be reinitialized with
\fBSHA1Init()\fR before it can be used again.
.RE

.SH SECURITY
.sp
.LP
The \fBSHA1\fR algorithm is also believed to have some weaknesses. Migration to
one of the \fBSHA2\fR algorithms-including \fBSHA256\fR, \fBSHA386\fR or
\fBSHA512\fR-is highly recommended when compatibility with data formats and on
wire protocols is permitted.
.SH RETURN VALUES
.sp
.LP
These functions do not return a value.
.SH EXAMPLES
.LP
\fBExample 1 \fRAuthenticate a message found in multiple buffers
.sp
.LP
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 \fBSHA1\fR digest.

.sp
.in +2
.nf
#include <sys/types.h>
#include <sys/uio.h>
#include <sha1.h>

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

    SHA1Init(&sha1_context);

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

    SHA1Final(auth_buffer, &sha1_context);

    return 0;
}
.fi
.in -2

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
\fBsha2\fR(3EXT), \fBlibmd\fR(3LIB)
.sp
.LP
RFC 1374