1 /* $NetBSD: md-sha256.c,v 1.3 2006/10/28 23:07:23 agc Exp $ */
2 /* $OpenBSD: md-sha256.c,v 1.5 2006/08/03 03:34:42 deraadt Exp $ */
4 * Copyright (c) 2005 Damien Miller <djm@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /* EVP wrapper for SHA256 */
21 __RCSID("$NetBSD: md-sha256.c,v 1.3 2006/10/28 23:07:23 agc Exp $");
23 #include <sys/types.h>
25 #include <openssl/evp.h>
30 const EVP_MD
*evp_ssh_sha256(void);
33 ssh_sha256_init(EVP_MD_CTX
*ctxt
)
35 SHA256_Init(ctxt
->md_data
);
40 ssh_sha256_update(EVP_MD_CTX
*ctxt
, const void *data
, size_t len
)
42 SHA256_Update(ctxt
->md_data
, data
, len
);
47 ssh_sha256_final(EVP_MD_CTX
*ctxt
, unsigned char *digest
)
49 SHA256_Final(digest
, ctxt
->md_data
);
54 ssh_sha256_cleanup(EVP_MD_CTX
*ctxt
)
56 memset(ctxt
->md_data
, 0, sizeof(SHA256_CTX
));
63 static EVP_MD ssh_sha256
;
65 memset(&ssh_sha256
, 0, sizeof(ssh_sha256
));
66 ssh_sha256
.type
= NID_undef
;
67 ssh_sha256
.md_size
= SHA256_DIGEST_LENGTH
;
68 ssh_sha256
.init
= ssh_sha256_init
;
69 ssh_sha256
.update
= ssh_sha256_update
;
70 ssh_sha256
.final
= ssh_sha256_final
;
71 ssh_sha256
.cleanup
= ssh_sha256_cleanup
;
72 ssh_sha256
.block_size
= SHA256_BLOCK_LENGTH
;
73 ssh_sha256
.ctx_size
= sizeof(SHA256_CTX
);