digest.h revision 1.2
10Sstevel@tonic-gate/*-
20Sstevel@tonic-gate * Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
30Sstevel@tonic-gate * All rights reserved.
40Sstevel@tonic-gate *
52256Sna195498 * Redistribution and use in source and binary forms, with or without
62256Sna195498 * modification, are permitted provided that the following conditions
70Sstevel@tonic-gate * are met:
80Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
90Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
100Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
110Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
120Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
150Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
160Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
170Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
180Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
190Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
200Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
212256Sna195498 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
222256Sna195498 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
232256Sna195498 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
242256Sna195498 */
252256Sna195498#ifndef DIGEST_H_
262256Sna195498#define DIGEST_H_	20100108
272256Sna195498
282256Sna195498#include <sys/types.h>
290Sstevel@tonic-gate
300Sstevel@tonic-gate#ifdef _KERNEL
310Sstevel@tonic-gate# include <sys/md5.h>
320Sstevel@tonic-gate# include <sys/sha1.h>
330Sstevel@tonic-gate# include <sys/sha2.h>
340Sstevel@tonic-gate# include <sys/rmd160.h>
350Sstevel@tonic-gate#else
360Sstevel@tonic-gate# include <md5.h>
370Sstevel@tonic-gate# include <sha1.h>
380Sstevel@tonic-gate# include <sha2.h>
390Sstevel@tonic-gate# include <rmd160.h>
400Sstevel@tonic-gate# include <inttypes.h>
410Sstevel@tonic-gate#endif
420Sstevel@tonic-gate
430Sstevel@tonic-gate#include "tiger.h"
440Sstevel@tonic-gate
450Sstevel@tonic-gate#ifndef __BEGIN_DECLS
460Sstevel@tonic-gate#  if defined(__cplusplus)
470Sstevel@tonic-gate#  define __BEGIN_DECLS           extern "C" {
480Sstevel@tonic-gate#  define __END_DECLS             }
490Sstevel@tonic-gate#  else
500Sstevel@tonic-gate#  define __BEGIN_DECLS
510Sstevel@tonic-gate#  define __END_DECLS
520Sstevel@tonic-gate#  endif
530Sstevel@tonic-gate#endif
540Sstevel@tonic-gate
550Sstevel@tonic-gate__BEGIN_DECLS
560Sstevel@tonic-gate
570Sstevel@tonic-gate#define MD5_HASH_ALG		1
580Sstevel@tonic-gate#define SHA1_HASH_ALG		2
590Sstevel@tonic-gate#define RIPEMD_HASH_ALG		3
600Sstevel@tonic-gate#define TIGER_HASH_ALG		6	/* from rfc2440 */
610Sstevel@tonic-gate#define SHA256_HASH_ALG		8
620Sstevel@tonic-gate#define SHA384_HASH_ALG		9
630Sstevel@tonic-gate#define SHA512_HASH_ALG		10
640Sstevel@tonic-gate#define SHA224_HASH_ALG		11
650Sstevel@tonic-gate#define TIGER2_HASH_ALG		100	/* private/experimental from rfc4880 */
660Sstevel@tonic-gate
670Sstevel@tonic-gate/* structure to describe digest methods */
680Sstevel@tonic-gatetypedef struct digest_t {
690Sstevel@tonic-gate	uint32_t		 alg;		/* algorithm */
700Sstevel@tonic-gate	size_t			 size;		/* size */
710Sstevel@tonic-gate	union {
720Sstevel@tonic-gate		MD5_CTX		 md5ctx;	/* MD5 */
730Sstevel@tonic-gate		SHA1_CTX	 sha1ctx;	/* SHA1 */
740Sstevel@tonic-gate		RMD160_CTX	 rmd160ctx;	/* RIPEMD */
750Sstevel@tonic-gate		SHA256_CTX	 sha256ctx;	/* SHA256 */
760Sstevel@tonic-gate		SHA512_CTX	 sha512ctx;	/* SHA512 */
770Sstevel@tonic-gate		TIGER_CTX	 tigerctx;	/* TIGER/TIGER2 */
780Sstevel@tonic-gate	} u;
790Sstevel@tonic-gate	void			*prefix;	/* points to specific prefix */
800Sstevel@tonic-gate	uint32_t		 len;		/* prefix length */
810Sstevel@tonic-gate	void			*ctx;		/* pointer to context array */
820Sstevel@tonic-gate} digest_t;
830Sstevel@tonic-gate
840Sstevel@tonic-gateunsigned digest_get_alg(const char */*hashalg*/);
850Sstevel@tonic-gate
860Sstevel@tonic-gateint digest_init(digest_t */*digest*/, const uint32_t /*hashalg*/);
870Sstevel@tonic-gate
880Sstevel@tonic-gateint digest_update(digest_t */*digest*/, const uint8_t */*data*/, size_t /*size*/);
890Sstevel@tonic-gateunsigned digest_final(uint8_t */*out*/, digest_t */*digest*/);
900Sstevel@tonic-gateint digest_alg_size(unsigned /*alg*/);
910Sstevel@tonic-gateint digest_length(digest_t */*hash*/, unsigned /*hashedlen*/);
920Sstevel@tonic-gate
930Sstevel@tonic-gatevoid MD5_Init(MD5_CTX */*context*/);
940Sstevel@tonic-gatevoid MD5_Update(MD5_CTX */*context*/, const unsigned char */*data*/, unsigned int /*len*/);
950Sstevel@tonic-gatevoid MD5_Final(unsigned char /*digest*/[16], MD5_CTX */*context*/);
960Sstevel@tonic-gate
970Sstevel@tonic-gatevoid SHA1_Init(SHA1_CTX */*context*/);
980Sstevel@tonic-gatevoid SHA1_Update(SHA1_CTX */*context*/, const unsigned char */*data*/, unsigned int /*len*/);
990Sstevel@tonic-gatevoid SHA1_Final(unsigned char /*digest*/[20], SHA1_CTX */*context*/);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gatevoid RMD160_Init(RMD160_CTX */*ctx*/);
1020Sstevel@tonic-gatevoid RMD160_Update(RMD160_CTX */*ctx*/, const unsigned char */*data*/, uint32_t /*len*/);
1030Sstevel@tonic-gatevoid RMD160_Final(unsigned char /*digest*/[RMD160_DIGEST_LENGTH], RMD160_CTX */*ctx*/);
1040Sstevel@tonic-gate
1050Sstevel@tonic-gateunsigned digest_get_prefix(unsigned /*hashalg*/, uint8_t */*prefix*/, size_t /*size*/);
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate__END_DECLS
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate#endif
1100Sstevel@tonic-gate