3 * Wrapper for builtin functions
5 * Copyright (c) 2001 Marko Kreen
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 void init_sha224(PX_MD
* h
);
40 void init_sha256(PX_MD
* h
);
41 void init_sha384(PX_MD
* h
);
42 void init_sha512(PX_MD
* h
);
47 int_sha224_len(PX_MD
* h
)
49 return SHA224_DIGEST_LENGTH
;
53 int_sha224_block_len(PX_MD
* h
)
55 return SHA224_BLOCK_LENGTH
;
59 int_sha224_update(PX_MD
* h
, const uint8
*data
, unsigned dlen
)
61 SHA224_CTX
*ctx
= (SHA224_CTX
*) h
->p
.ptr
;
63 SHA224_Update(ctx
, data
, dlen
);
67 int_sha224_reset(PX_MD
* h
)
69 SHA224_CTX
*ctx
= (SHA224_CTX
*) h
->p
.ptr
;
75 int_sha224_finish(PX_MD
* h
, uint8
*dst
)
77 SHA224_CTX
*ctx
= (SHA224_CTX
*) h
->p
.ptr
;
79 SHA224_Final(dst
, ctx
);
83 int_sha224_free(PX_MD
* h
)
85 SHA224_CTX
*ctx
= (SHA224_CTX
*) h
->p
.ptr
;
87 memset(ctx
, 0, sizeof(*ctx
));
95 int_sha256_len(PX_MD
* h
)
97 return SHA256_DIGEST_LENGTH
;
101 int_sha256_block_len(PX_MD
* h
)
103 return SHA256_BLOCK_LENGTH
;
107 int_sha256_update(PX_MD
* h
, const uint8
*data
, unsigned dlen
)
109 SHA256_CTX
*ctx
= (SHA256_CTX
*) h
->p
.ptr
;
111 SHA256_Update(ctx
, data
, dlen
);
115 int_sha256_reset(PX_MD
* h
)
117 SHA256_CTX
*ctx
= (SHA256_CTX
*) h
->p
.ptr
;
123 int_sha256_finish(PX_MD
* h
, uint8
*dst
)
125 SHA256_CTX
*ctx
= (SHA256_CTX
*) h
->p
.ptr
;
127 SHA256_Final(dst
, ctx
);
131 int_sha256_free(PX_MD
* h
)
133 SHA256_CTX
*ctx
= (SHA256_CTX
*) h
->p
.ptr
;
135 memset(ctx
, 0, sizeof(*ctx
));
143 int_sha384_len(PX_MD
* h
)
145 return SHA384_DIGEST_LENGTH
;
149 int_sha384_block_len(PX_MD
* h
)
151 return SHA384_BLOCK_LENGTH
;
155 int_sha384_update(PX_MD
* h
, const uint8
*data
, unsigned dlen
)
157 SHA384_CTX
*ctx
= (SHA384_CTX
*) h
->p
.ptr
;
159 SHA384_Update(ctx
, data
, dlen
);
163 int_sha384_reset(PX_MD
* h
)
165 SHA384_CTX
*ctx
= (SHA384_CTX
*) h
->p
.ptr
;
171 int_sha384_finish(PX_MD
* h
, uint8
*dst
)
173 SHA384_CTX
*ctx
= (SHA384_CTX
*) h
->p
.ptr
;
175 SHA384_Final(dst
, ctx
);
179 int_sha384_free(PX_MD
* h
)
181 SHA384_CTX
*ctx
= (SHA384_CTX
*) h
->p
.ptr
;
183 memset(ctx
, 0, sizeof(*ctx
));
191 int_sha512_len(PX_MD
* h
)
193 return SHA512_DIGEST_LENGTH
;
197 int_sha512_block_len(PX_MD
* h
)
199 return SHA512_BLOCK_LENGTH
;
203 int_sha512_update(PX_MD
* h
, const uint8
*data
, unsigned dlen
)
205 SHA512_CTX
*ctx
= (SHA512_CTX
*) h
->p
.ptr
;
207 SHA512_Update(ctx
, data
, dlen
);
211 int_sha512_reset(PX_MD
* h
)
213 SHA512_CTX
*ctx
= (SHA512_CTX
*) h
->p
.ptr
;
219 int_sha512_finish(PX_MD
* h
, uint8
*dst
)
221 SHA512_CTX
*ctx
= (SHA512_CTX
*) h
->p
.ptr
;
223 SHA512_Final(dst
, ctx
);
227 int_sha512_free(PX_MD
* h
)
229 SHA512_CTX
*ctx
= (SHA512_CTX
*) h
->p
.ptr
;
231 memset(ctx
, 0, sizeof(*ctx
));
239 init_sha224(PX_MD
* md
)
243 ctx
= px_alloc(sizeof(*ctx
));
244 memset(ctx
, 0, sizeof(*ctx
));
248 md
->result_size
= int_sha224_len
;
249 md
->block_size
= int_sha224_block_len
;
250 md
->reset
= int_sha224_reset
;
251 md
->update
= int_sha224_update
;
252 md
->finish
= int_sha224_finish
;
253 md
->free
= int_sha224_free
;
259 init_sha256(PX_MD
* md
)
263 ctx
= px_alloc(sizeof(*ctx
));
264 memset(ctx
, 0, sizeof(*ctx
));
268 md
->result_size
= int_sha256_len
;
269 md
->block_size
= int_sha256_block_len
;
270 md
->reset
= int_sha256_reset
;
271 md
->update
= int_sha256_update
;
272 md
->finish
= int_sha256_finish
;
273 md
->free
= int_sha256_free
;
279 init_sha384(PX_MD
* md
)
283 ctx
= px_alloc(sizeof(*ctx
));
284 memset(ctx
, 0, sizeof(*ctx
));
288 md
->result_size
= int_sha384_len
;
289 md
->block_size
= int_sha384_block_len
;
290 md
->reset
= int_sha384_reset
;
291 md
->update
= int_sha384_update
;
292 md
->finish
= int_sha384_finish
;
293 md
->free
= int_sha384_free
;
299 init_sha512(PX_MD
* md
)
303 ctx
= px_alloc(sizeof(*ctx
));
304 memset(ctx
, 0, sizeof(*ctx
));
308 md
->result_size
= int_sha512_len
;
309 md
->block_size
= int_sha512_block_len
;
310 md
->reset
= int_sha512_reset
;
311 md
->update
= int_sha512_update
;
312 md
->finish
= int_sha512_finish
;
313 md
->free
= int_sha512_free
;