digest.h revision 1.1.4.2
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#include "tiger.h" 37 38#ifndef __BEGIN_DECLS 39# if defined(__cplusplus) 40# define __BEGIN_DECLS extern "C" { 41# define __END_DECLS } 42# else 43# define __BEGIN_DECLS 44# define __END_DECLS 45# endif 46#endif 47 48__BEGIN_DECLS 49 50#define MD5_HASH_ALG 1 51#define SHA1_HASH_ALG 2 52#define RIPEMD_HASH_ALG 3 53#define TIGER_HASH_ALG 6 /* from rfc2440 */ 54#define SHA256_HASH_ALG 8 55#define SHA384_HASH_ALG 9 56#define SHA512_HASH_ALG 10 57#define SHA224_HASH_ALG 11 58#define TIGER2_HASH_ALG 100 /* private/experimental from rfc4880 */ 59 60/* structure to describe digest methods */ 61typedef struct digest_t { 62 uint32_t alg; /* algorithm */ 63 size_t size; /* size */ 64 union { 65 MD5_CTX md5ctx; /* MD5 */ 66 SHA1_CTX sha1ctx; /* SHA1 */ 67 RMD160_CTX rmd160ctx; /* RIPEMD */ 68 SHA256_CTX sha256ctx; /* SHA256 */ 69 SHA512_CTX sha512ctx; /* SHA512 */ 70 TIGER_CTX tigerctx; /* TIGER/TIGER2 */ 71 } u; 72 void *prefix; /* points to specific prefix */ 73 uint32_t len; /* prefix length */ 74 void *ctx; /* pointer to context array */ 75} digest_t; 76 77unsigned digest_get_alg(const char */*hashalg*/); 78 79int digest_init(digest_t */*digest*/, const uint32_t /*hashalg*/); 80 81int digest_update(digest_t */*digest*/, const uint8_t */*data*/, size_t /*size*/); 82unsigned digest_final(uint8_t */*out*/, digest_t */*digest*/); 83int digest_alg_size(unsigned /*alg*/); 84int digest_length(digest_t */*hash*/, unsigned /*hashedlen*/); 85 86unsigned digest_get_prefix(unsigned /*hashalg*/, uint8_t */*prefix*/, size_t /*size*/); 87 88__END_DECLS 89 90#endif 91