1/* 2 * Copyright (C) 2005-2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17/* $Id: hmacsha.h,v 1.9 2009/02/06 23:47:42 tbox Exp $ */ 18 19/*! \file isc/hmacsha.h 20 * This is the header file for the HMAC-SHA1, HMAC-SHA224, HMAC-SHA256, 21 * HMAC-SHA334 and HMAC-SHA512 hash algorithm described in RFC 2104. 22 */ 23 24#ifndef ISC_HMACSHA_H 25#define ISC_HMACSHA_H 1 26 27#include <isc/lang.h> 28#include <isc/platform.h> 29#include <isc/sha1.h> 30#include <isc/sha2.h> 31#include <isc/types.h> 32 33#define ISC_HMACSHA1_KEYLENGTH ISC_SHA1_BLOCK_LENGTH 34#define ISC_HMACSHA224_KEYLENGTH ISC_SHA224_BLOCK_LENGTH 35#define ISC_HMACSHA256_KEYLENGTH ISC_SHA256_BLOCK_LENGTH 36#define ISC_HMACSHA384_KEYLENGTH ISC_SHA384_BLOCK_LENGTH 37#define ISC_HMACSHA512_KEYLENGTH ISC_SHA512_BLOCK_LENGTH 38 39#ifdef ISC_PLATFORM_OPENSSLHASH 40#include <openssl/hmac.h> 41 42typedef HMAC_CTX isc_hmacsha1_t; 43typedef HMAC_CTX isc_hmacsha224_t; 44typedef HMAC_CTX isc_hmacsha256_t; 45typedef HMAC_CTX isc_hmacsha384_t; 46typedef HMAC_CTX isc_hmacsha512_t; 47 48#else 49 50typedef struct { 51 isc_sha1_t sha1ctx; 52 unsigned char key[ISC_HMACSHA1_KEYLENGTH]; 53} isc_hmacsha1_t; 54 55typedef struct { 56 isc_sha224_t sha224ctx; 57 unsigned char key[ISC_HMACSHA224_KEYLENGTH]; 58} isc_hmacsha224_t; 59 60typedef struct { 61 isc_sha256_t sha256ctx; 62 unsigned char key[ISC_HMACSHA256_KEYLENGTH]; 63} isc_hmacsha256_t; 64 65typedef struct { 66 isc_sha384_t sha384ctx; 67 unsigned char key[ISC_HMACSHA384_KEYLENGTH]; 68} isc_hmacsha384_t; 69 70typedef struct { 71 isc_sha512_t sha512ctx; 72 unsigned char key[ISC_HMACSHA512_KEYLENGTH]; 73} isc_hmacsha512_t; 74#endif 75 76ISC_LANG_BEGINDECLS 77 78void 79isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key, 80 unsigned int len); 81 82void 83isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx); 84 85void 86isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf, 87 unsigned int len); 88 89void 90isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len); 91 92isc_boolean_t 93isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len); 94 95 96void 97isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key, 98 unsigned int len); 99 100void 101isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx); 102 103void 104isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf, 105 unsigned int len); 106 107void 108isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len); 109 110isc_boolean_t 111isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len); 112 113 114void 115isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key, 116 unsigned int len); 117 118void 119isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx); 120 121void 122isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf, 123 unsigned int len); 124 125void 126isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len); 127 128isc_boolean_t 129isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len); 130 131 132void 133isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key, 134 unsigned int len); 135 136void 137isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx); 138 139void 140isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf, 141 unsigned int len); 142 143void 144isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len); 145 146isc_boolean_t 147isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len); 148 149 150void 151isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key, 152 unsigned int len); 153 154void 155isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx); 156 157void 158isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf, 159 unsigned int len); 160 161void 162isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len); 163 164isc_boolean_t 165isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len); 166 167ISC_LANG_ENDDECLS 168 169#endif /* ISC_HMACSHA_H */ 170