1/*-
2 * Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#ifndef DIGEST_H_
26#define DIGEST_H_	20100108
27
28#include <sys/types.h>
29
30#include <inttypes.h>
31
32#include "md5.h"
33#include "sha1.h"
34#include "sha2.h"
35#include "rmd160.h"
36
37#ifndef __BEGIN_DECLS
38#  if defined(__cplusplus)
39#  define __BEGIN_DECLS           extern "C" {
40#  define __END_DECLS             }
41#  else
42#  define __BEGIN_DECLS
43#  define __END_DECLS
44#  endif
45#endif
46
47__BEGIN_DECLS
48
49#define MD5_HASH_ALG		1
50#define SHA1_HASH_ALG		2
51#define RIPEMD_HASH_ALG		3
52#define SHA256_HASH_ALG		8
53#define SHA384_HASH_ALG		9
54#define SHA512_HASH_ALG		10
55#define SHA224_HASH_ALG		11
56
57/* structure to describe digest methods */
58typedef struct digest_t {
59	uint32_t		 alg;		/* algorithm */
60	size_t			 size;		/* size */
61	union {
62		NETPGPV_MD5_CTX		 md5ctx;	/* MD5 */
63		NETPGPV_SHA1_CTX	 sha1ctx;	/* SHA1 */
64		NETPGPV_RMD160_CTX	 rmd160ctx;	/* RIPEMD */
65		NETPGPV_SHA256_CTX	 sha256ctx;	/* SHA256 */
66		NETPGPV_SHA512_CTX	 sha512ctx;	/* SHA512 */
67	} u;
68	void			*prefix;	/* points to specific prefix */
69	uint32_t		 len;		/* prefix length */
70	void			*ctx;		/* pointer to context array */
71} digest_t;
72
73unsigned digest_get_alg(const char */*hashalg*/);
74
75int digest_init(digest_t */*digest*/, const uint32_t /*hashalg*/);
76
77int digest_update(digest_t */*digest*/, const uint8_t */*data*/, size_t /*size*/);
78unsigned digest_final(uint8_t */*out*/, digest_t */*digest*/);
79int digest_alg_size(unsigned /*alg*/);
80int digest_length(digest_t */*hash*/, unsigned /*hashedlen*/);
81
82unsigned digest_get_prefix(unsigned /*hashalg*/, uint8_t */*prefix*/, size_t /*size*/);
83
84__END_DECLS
85
86#endif
87