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