OLD | NEW |
| (Empty) |
1 /* | |
2 * sha1.h | |
3 * | |
4 * interface to the Secure Hash Algorithm v.1 (SHA-1), specified in | |
5 * FIPS 180-1 | |
6 * | |
7 * David A. McGrew | |
8 * Cisco Systems, Inc. | |
9 */ | |
10 | |
11 /* | |
12 * | |
13 * Copyright (c) 2001-2006, Cisco Systems, Inc. | |
14 * All rights reserved. | |
15 * | |
16 * Redistribution and use in source and binary forms, with or without | |
17 * modification, are permitted provided that the following conditions | |
18 * are met: | |
19 * | |
20 * Redistributions of source code must retain the above copyright | |
21 * notice, this list of conditions and the following disclaimer. | |
22 * | |
23 * Redistributions in binary form must reproduce the above | |
24 * copyright notice, this list of conditions and the following | |
25 * disclaimer in the documentation and/or other materials provided | |
26 * with the distribution. | |
27 * | |
28 * Neither the name of the Cisco Systems, Inc. nor the names of its | |
29 * contributors may be used to endorse or promote products derived | |
30 * from this software without specific prior written permission. | |
31 * | |
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
36 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
39 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
43 * OF THE POSSIBILITY OF SUCH DAMAGE. | |
44 * | |
45 */ | |
46 | |
47 #ifndef SHA1_H | |
48 #define SHA1_H | |
49 | |
50 #ifdef HAVE_CONFIG_H | |
51 #include <config.h> | |
52 #endif | |
53 | |
54 #include "err.h" | |
55 #ifdef OPENSSL | |
56 #include <openssl/evp.h> | |
57 #include <stdint.h> | |
58 | |
59 typedef EVP_MD_CTX sha1_ctx_t; | |
60 | |
61 /* | |
62 * sha1_init(&ctx) initializes the SHA1 context ctx | |
63 * | |
64 * sha1_update(&ctx, msg, len) hashes the len octets starting at msg | |
65 * into the SHA1 context | |
66 * | |
67 * sha1_final(&ctx, output) performs the final processing of the SHA1 | |
68 * context and writes the result to the 20 octets at output | |
69 * | |
70 * Return values are ignored on the EVP functions since all three | |
71 * of these functions return void. | |
72 * | |
73 */ | |
74 | |
75 static inline void sha1_init (sha1_ctx_t *ctx) | |
76 { | |
77 EVP_MD_CTX_init(ctx); | |
78 EVP_DigestInit(ctx, EVP_sha1()); | |
79 } | |
80 | |
81 static inline void sha1_update (sha1_ctx_t *ctx, const uint8_t *M, int octets_in
_msg) | |
82 { | |
83 EVP_DigestUpdate(ctx, M, octets_in_msg); | |
84 } | |
85 | |
86 static inline void sha1_final (sha1_ctx_t *ctx, uint32_t *output) | |
87 { | |
88 unsigned int len = 0; | |
89 | |
90 EVP_DigestFinal(ctx, (unsigned char*)output, &len); | |
91 } | |
92 #else | |
93 #include "datatypes.h" | |
94 | |
95 typedef struct { | |
96 uint32_t H[5]; /* state vector */ | |
97 uint32_t M[16]; /* message buffer */ | |
98 int octets_in_buffer; /* octets of message in buffer */ | |
99 uint32_t num_bits_in_msg; /* total number of bits in message */ | |
100 } sha1_ctx_t; | |
101 | |
102 /* | |
103 * sha1(&ctx, msg, len, output) hashes the len octets starting at msg | |
104 * into the SHA1 context, then writes the result to the 20 octets at | |
105 * output | |
106 * | |
107 */ | |
108 | |
109 void | |
110 sha1(const uint8_t *message, int octets_in_msg, uint32_t output[5]); | |
111 | |
112 /* | |
113 * sha1_init(&ctx) initializes the SHA1 context ctx | |
114 * | |
115 * sha1_update(&ctx, msg, len) hashes the len octets starting at msg | |
116 * into the SHA1 context | |
117 * | |
118 * sha1_final(&ctx, output) performs the final processing of the SHA1 | |
119 * context and writes the result to the 20 octets at output | |
120 * | |
121 */ | |
122 | |
123 void | |
124 sha1_init(sha1_ctx_t *ctx); | |
125 | |
126 void | |
127 sha1_update(sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg); | |
128 | |
129 void | |
130 sha1_final(sha1_ctx_t *ctx, uint32_t output[5]); | |
131 | |
132 /* | |
133 * The sha1_core function is INTERNAL to SHA-1, but it is declared | |
134 * here because it is also used by the cipher SEAL 3.0 in its key | |
135 * setup algorithm. | |
136 */ | |
137 | |
138 /* | |
139 * sha1_core(M, H) computes the core sha1 compression function, where M is | |
140 * the next part of the message and H is the intermediate state {H0, | |
141 * H1, ...} | |
142 * | |
143 * this function does not do any of the padding required in the | |
144 * complete sha1 function | |
145 */ | |
146 | |
147 void | |
148 sha1_core(const uint32_t M[16], uint32_t hash_value[5]); | |
149 | |
150 #endif /* else OPENSSL */ | |
151 | |
152 #endif /* SHA1_H */ | |
OLD | NEW |