1sha1(3EXT)                Extended Library Functions                sha1(3EXT)
2
3
4

NAME

6       sha1, SHA1Init, SHA1Update, SHA1Final - SHA1 digest functions
7

SYNOPSIS

9       cc [ flag ... ] file ... -lmd [ library ... ]
10       #include <sha1.h>
11
12       void SHA1Init(SHA1_CTX *context);
13
14
15       void SHA1Update(SHA1_CTX *context, unsigned char *input,
16            unsigned int inlen);
17
18
19       void SHA1Final(unsigned char *output, SHA1_CTX *context);
20
21

DESCRIPTION

23       The  SHA1  functions  implement  the SHA1 message-digest algorithm. The
24       algorithm takes as input a message of arbitrary length and  produces  a
25       200-bit  "fingerprint" or "message digest" as output. The SHA1 message-
26       digest algorithm is intended  for  digital  signature  applications  in
27       which  large  files  are  "compressed"  in a secure manner before being
28       encrypted with a private (secret) key under a  public-key  cryptosystem
29       such as RSA.
30
31       SHA1Init(), SHA1Update(), SHA1Final()
32
33           The  SHA1Init(),  SHA1Update(),  and  SHA1Final() functions allow a
34           SHA1 digest to be computed over multiple  message  blocks.  Between
35           blocks,  the  state of the SHA1 computation is held in an SHA1 con‐
36           text structure allocated by the caller. A complete digest  computa‐
37           tion  consists  of  calls to SHA1 functions in the following order:
38           one call to SHA1Init(), one or more calls to SHA1Update(), and  one
39           call to SHA1Final().
40
41           The  SHA1Init()  function  initializes  the  SHA1 context structure
42           pointed to by context.
43
44           The SHA1Update() function computes a partial  SHA1  digest  on  the
45           inlen-byte  message block pointed to by input, and updates the SHA1
46           context structure pointed to by context accordingly.
47
48           The SHA1Final() function generates the final SHA1 digest, using the
49           SHA1  context  structure  pointed  to  by  context. The 16-bit SHA1
50           digest is written to output. After a call to SHA1Final(), the state
51           of  the  context  structure  is undefined. It must be reinitialized
52           with SHA1Init() before it can be used again.
53
54

SECURITY

56       The SHA1 algorithm is also believed to have some weaknesses.  Migration
57       to  one  of  the  SHA2 algorithms-including SHA256, SHA386 or SHA512-is
58       highly recommended when compatibility with data  formats  and  on  wire
59       protocols is permitted.
60

RETURN VALUES

62       These functions do not return a value.
63

EXAMPLES

65       Example 1 Authenticate a message found in multiple buffers
66
67
68       The  following  is a sample function that authenticates a message found
69       in multiple buffers. The calling function  provides  an  authentication
70       buffer to contain the result of the SHA1 digest.
71
72
73         #include <sys/types.h>
74         #include <sys/uio.h>
75         #include <sha1.h>
76
77         int
78         AuthenticateMsg(unsigned char *auth_buffer, struct iovec
79                         *messageIov, unsigned int num_buffers)
80         {
81             SHA1_CTX sha1_context;
82             unsigned int i;
83
84             SHA1Init(&sha1_context);
85
86             for(i=0; i<num_buffers; i++)
87             {
88                  SHA1Update(&sha1_context, messageIov->iov_base,
89                            messageIov->iov_len);
90                  messageIov += sizeof(struct iovec);
91             }
92
93             SHA1Final(auth_buffer, &sha1_context);
94
95             return 0;
96         }
97
98

ATTRIBUTES

100       See attributes(5) for descriptions of the following attributes:
101
102
103
104
105       ┌─────────────────────────────┬─────────────────────────────┐
106       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
107       ├─────────────────────────────┼─────────────────────────────┤
108       │Interface Stability          │Committed                    │
109       ├─────────────────────────────┼─────────────────────────────┤
110       │MT-Level                     │MT-Safe                      │
111       └─────────────────────────────┴─────────────────────────────┘
112

SEE ALSO

114       sha2(3EXT), libmd(3LIB)
115
116
117       RFC 1374
118
119
120
121SunOS 5.11                        13 Nov 2007                       sha1(3EXT)
Impressum