1290001Sglebius/* 2290001Sglebius * Copyright (C) 2005-2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3290001Sglebius * 4290001Sglebius * Permission to use, copy, modify, and/or distribute this software for any 5290001Sglebius * purpose with or without fee is hereby granted, provided that the above 6290001Sglebius * copyright notice and this permission notice appear in all copies. 7290001Sglebius * 8290001Sglebius * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9290001Sglebius * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10290001Sglebius * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11290001Sglebius * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12290001Sglebius * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13290001Sglebius * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14290001Sglebius * PERFORMANCE OF THIS SOFTWARE. 15290001Sglebius */ 16290001Sglebius 17290001Sglebius/* $Id: hmacsha.h,v 1.9 2009/02/06 23:47:42 tbox Exp $ */ 18290001Sglebius 19290001Sglebius/*! \file isc/hmacsha.h 20290001Sglebius * This is the header file for the HMAC-SHA1, HMAC-SHA224, HMAC-SHA256, 21290001Sglebius * HMAC-SHA334 and HMAC-SHA512 hash algorithm described in RFC 2104. 22290001Sglebius */ 23290001Sglebius 24290001Sglebius#ifndef ISC_HMACSHA_H 25290001Sglebius#define ISC_HMACSHA_H 1 26290001Sglebius 27290001Sglebius#include <isc/lang.h> 28290001Sglebius#include <isc/platform.h> 29290001Sglebius#include <isc/sha1.h> 30290001Sglebius#include <isc/sha2.h> 31290001Sglebius#include <isc/types.h> 32290001Sglebius 33290001Sglebius#define ISC_HMACSHA1_KEYLENGTH ISC_SHA1_BLOCK_LENGTH 34290001Sglebius#define ISC_HMACSHA224_KEYLENGTH ISC_SHA224_BLOCK_LENGTH 35290001Sglebius#define ISC_HMACSHA256_KEYLENGTH ISC_SHA256_BLOCK_LENGTH 36290001Sglebius#define ISC_HMACSHA384_KEYLENGTH ISC_SHA384_BLOCK_LENGTH 37290001Sglebius#define ISC_HMACSHA512_KEYLENGTH ISC_SHA512_BLOCK_LENGTH 38290001Sglebius 39290001Sglebius#ifdef ISC_PLATFORM_OPENSSLHASH 40290001Sglebius#include <openssl/hmac.h> 41290001Sglebius 42290001Sglebiustypedef HMAC_CTX isc_hmacsha1_t; 43290001Sglebiustypedef HMAC_CTX isc_hmacsha224_t; 44290001Sglebiustypedef HMAC_CTX isc_hmacsha256_t; 45290001Sglebiustypedef HMAC_CTX isc_hmacsha384_t; 46290001Sglebiustypedef HMAC_CTX isc_hmacsha512_t; 47290001Sglebius 48290001Sglebius#else 49290001Sglebius 50290001Sglebiustypedef struct { 51290001Sglebius isc_sha1_t sha1ctx; 52290001Sglebius unsigned char key[ISC_HMACSHA1_KEYLENGTH]; 53290001Sglebius} isc_hmacsha1_t; 54290001Sglebius 55290001Sglebiustypedef struct { 56290001Sglebius isc_sha224_t sha224ctx; 57290001Sglebius unsigned char key[ISC_HMACSHA224_KEYLENGTH]; 58290001Sglebius} isc_hmacsha224_t; 59290001Sglebius 60290001Sglebiustypedef struct { 61290001Sglebius isc_sha256_t sha256ctx; 62290001Sglebius unsigned char key[ISC_HMACSHA256_KEYLENGTH]; 63290001Sglebius} isc_hmacsha256_t; 64290001Sglebius 65290001Sglebiustypedef struct { 66290001Sglebius isc_sha384_t sha384ctx; 67290001Sglebius unsigned char key[ISC_HMACSHA384_KEYLENGTH]; 68290001Sglebius} isc_hmacsha384_t; 69290001Sglebius 70290001Sglebiustypedef struct { 71290001Sglebius isc_sha512_t sha512ctx; 72290001Sglebius unsigned char key[ISC_HMACSHA512_KEYLENGTH]; 73290001Sglebius} isc_hmacsha512_t; 74290001Sglebius#endif 75290001Sglebius 76290001SglebiusISC_LANG_BEGINDECLS 77290001Sglebius 78290001Sglebiusvoid 79290001Sglebiusisc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key, 80290001Sglebius unsigned int len); 81290001Sglebius 82290001Sglebiusvoid 83290001Sglebiusisc_hmacsha1_invalidate(isc_hmacsha1_t *ctx); 84290001Sglebius 85290001Sglebiusvoid 86290001Sglebiusisc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf, 87290001Sglebius unsigned int len); 88290001Sglebius 89290001Sglebiusvoid 90290001Sglebiusisc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len); 91290001Sglebius 92290001Sglebiusisc_boolean_t 93290001Sglebiusisc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len); 94290001Sglebius 95290001Sglebius 96290001Sglebiusvoid 97290001Sglebiusisc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key, 98290001Sglebius unsigned int len); 99290001Sglebius 100290001Sglebiusvoid 101290001Sglebiusisc_hmacsha224_invalidate(isc_hmacsha224_t *ctx); 102290001Sglebius 103290001Sglebiusvoid 104290001Sglebiusisc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf, 105290001Sglebius unsigned int len); 106290001Sglebius 107290001Sglebiusvoid 108290001Sglebiusisc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len); 109290001Sglebius 110290001Sglebiusisc_boolean_t 111290001Sglebiusisc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len); 112290001Sglebius 113290001Sglebius 114290001Sglebiusvoid 115290001Sglebiusisc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key, 116290001Sglebius unsigned int len); 117290001Sglebius 118290001Sglebiusvoid 119290001Sglebiusisc_hmacsha256_invalidate(isc_hmacsha256_t *ctx); 120290001Sglebius 121290001Sglebiusvoid 122290001Sglebiusisc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf, 123290001Sglebius unsigned int len); 124290001Sglebius 125290001Sglebiusvoid 126290001Sglebiusisc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len); 127290001Sglebius 128290001Sglebiusisc_boolean_t 129290001Sglebiusisc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len); 130290001Sglebius 131290001Sglebius 132290001Sglebiusvoid 133290001Sglebiusisc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key, 134290001Sglebius unsigned int len); 135290001Sglebius 136290001Sglebiusvoid 137290001Sglebiusisc_hmacsha384_invalidate(isc_hmacsha384_t *ctx); 138290001Sglebius 139290001Sglebiusvoid 140290001Sglebiusisc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf, 141290001Sglebius unsigned int len); 142290001Sglebius 143290001Sglebiusvoid 144290001Sglebiusisc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len); 145290001Sglebius 146290001Sglebiusisc_boolean_t 147290001Sglebiusisc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len); 148290001Sglebius 149290001Sglebius 150290001Sglebiusvoid 151290001Sglebiusisc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key, 152290001Sglebius unsigned int len); 153290001Sglebius 154290001Sglebiusvoid 155290001Sglebiusisc_hmacsha512_invalidate(isc_hmacsha512_t *ctx); 156290001Sglebius 157290001Sglebiusvoid 158290001Sglebiusisc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf, 159290001Sglebius unsigned int len); 160290001Sglebius 161290001Sglebiusvoid 162290001Sglebiusisc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len); 163290001Sglebius 164290001Sglebiusisc_boolean_t 165290001Sglebiusisc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len); 166290001Sglebius 167290001SglebiusISC_LANG_ENDDECLS 168290001Sglebius 169290001Sglebius#endif /* ISC_HMACSHA_H */ 170