xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/netpgpverify/digest.h (revision 32d959bfe02e9d3b89de38473374c06cf0ea0ac2)
125f78d91Sagc /*-
225f78d91Sagc  * Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
325f78d91Sagc  * All rights reserved.
425f78d91Sagc  *
525f78d91Sagc  * Redistribution and use in source and binary forms, with or without
625f78d91Sagc  * modification, are permitted provided that the following conditions
725f78d91Sagc  * are met:
825f78d91Sagc  * 1. Redistributions of source code must retain the above copyright
925f78d91Sagc  *    notice, this list of conditions and the following disclaimer.
1025f78d91Sagc  * 2. Redistributions in binary form must reproduce the above copyright
1125f78d91Sagc  *    notice, this list of conditions and the following disclaimer in the
1225f78d91Sagc  *    documentation and/or other materials provided with the distribution.
1325f78d91Sagc  *
1425f78d91Sagc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1525f78d91Sagc  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1625f78d91Sagc  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1725f78d91Sagc  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1825f78d91Sagc  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1925f78d91Sagc  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2025f78d91Sagc  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2125f78d91Sagc  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2225f78d91Sagc  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2325f78d91Sagc  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2425f78d91Sagc  */
2525f78d91Sagc #ifndef DIGEST_H_
2625f78d91Sagc #define DIGEST_H_	20100108
2725f78d91Sagc 
2825f78d91Sagc #include <sys/types.h>
2925f78d91Sagc 
3025f78d91Sagc #include <inttypes.h>
3125f78d91Sagc 
3225f78d91Sagc #include "md5.h"
3325f78d91Sagc #include "sha1.h"
3425f78d91Sagc #include "sha2.h"
3525f78d91Sagc #include "rmd160.h"
3625f78d91Sagc 
3725f78d91Sagc #ifndef __BEGIN_DECLS
3825f78d91Sagc #  if defined(__cplusplus)
3925f78d91Sagc #  define __BEGIN_DECLS           extern "C" {
4025f78d91Sagc #  define __END_DECLS             }
4125f78d91Sagc #  else
4225f78d91Sagc #  define __BEGIN_DECLS
4325f78d91Sagc #  define __END_DECLS
4425f78d91Sagc #  endif
4525f78d91Sagc #endif
4625f78d91Sagc 
4725f78d91Sagc __BEGIN_DECLS
4825f78d91Sagc 
4925f78d91Sagc #define MD5_HASH_ALG		1
5025f78d91Sagc #define SHA1_HASH_ALG		2
5125f78d91Sagc #define RIPEMD_HASH_ALG		3
5225f78d91Sagc #define SHA256_HASH_ALG		8
5325f78d91Sagc #define SHA384_HASH_ALG		9
5425f78d91Sagc #define SHA512_HASH_ALG		10
5525f78d91Sagc #define SHA224_HASH_ALG		11
5625f78d91Sagc 
5725f78d91Sagc /* structure to describe digest methods */
5825f78d91Sagc typedef struct digest_t {
5925f78d91Sagc 	uint32_t		 alg;		/* algorithm */
6025f78d91Sagc 	size_t			 size;		/* size */
6125f78d91Sagc 	union {
62*dd98b26dSagc 		NETPGPV_MD5_CTX		 md5ctx;	/* MD5 */
63*dd98b26dSagc 		NETPGPV_SHA1_CTX	 sha1ctx;	/* SHA1 */
64*dd98b26dSagc 		NETPGPV_RMD160_CTX	 rmd160ctx;	/* RIPEMD */
65*dd98b26dSagc 		NETPGPV_SHA256_CTX	 sha256ctx;	/* SHA256 */
66*dd98b26dSagc 		NETPGPV_SHA512_CTX	 sha512ctx;	/* SHA512 */
6725f78d91Sagc 	} u;
6825f78d91Sagc 	void			*prefix;	/* points to specific prefix */
6925f78d91Sagc 	uint32_t		 len;		/* prefix length */
7025f78d91Sagc 	void			*ctx;		/* pointer to context array */
7125f78d91Sagc } digest_t;
7225f78d91Sagc 
7325f78d91Sagc unsigned digest_get_alg(const char */*hashalg*/);
7425f78d91Sagc 
7525f78d91Sagc int digest_init(digest_t */*digest*/, const uint32_t /*hashalg*/);
7625f78d91Sagc 
7725f78d91Sagc int digest_update(digest_t */*digest*/, const uint8_t */*data*/, size_t /*size*/);
7825f78d91Sagc unsigned digest_final(uint8_t */*out*/, digest_t */*digest*/);
7925f78d91Sagc int digest_alg_size(unsigned /*alg*/);
8025f78d91Sagc int digest_length(digest_t */*hash*/, unsigned /*hashedlen*/);
8125f78d91Sagc 
8225f78d91Sagc unsigned digest_get_prefix(unsigned /*hashalg*/, uint8_t */*prefix*/, size_t /*size*/);
8325f78d91Sagc 
8425f78d91Sagc __END_DECLS
8525f78d91Sagc 
8625f78d91Sagc #endif
87