hmacsha.h 4.41 KB
Newer Older
1
/*
2
 * Copyright (C) 2005-2007, 2009, 2014, 2016-2018  Internet Systems Consortium, Inc. ("ISC")
3
 *
4 5 6
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 8
 */

Automatic Updater's avatar
Automatic Updater committed
9
/* $Id: hmacsha.h,v 1.9 2009/02/06 23:47:42 tbox Exp $ */
10

11
/*! \file isc/hmacsha.h
12 13 14 15 16 17 18 19
 * This is the header file for the HMAC-SHA1, HMAC-SHA224, HMAC-SHA256,
 * HMAC-SHA334 and HMAC-SHA512 hash algorithm described in RFC 2104.
 */

#ifndef ISC_HMACSHA_H
#define ISC_HMACSHA_H 1

#include <isc/lang.h>
Francis Dupont's avatar
Francis Dupont committed
20
#include <isc/platform.h>
21 22 23 24
#include <isc/sha1.h>
#include <isc/sha2.h>
#include <isc/types.h>

25 26 27 28 29
#define ISC_HMACSHA1_KEYLENGTH ISC_SHA1_BLOCK_LENGTH
#define ISC_HMACSHA224_KEYLENGTH ISC_SHA224_BLOCK_LENGTH
#define ISC_HMACSHA256_KEYLENGTH ISC_SHA256_BLOCK_LENGTH
#define ISC_HMACSHA384_KEYLENGTH ISC_SHA384_BLOCK_LENGTH
#define ISC_HMACSHA512_KEYLENGTH ISC_SHA512_BLOCK_LENGTH
30

Francis Dupont's avatar
Francis Dupont committed
31
#ifdef ISC_PLATFORM_OPENSSLHASH
32
#include <openssl/opensslv.h>
Francis Dupont's avatar
Francis Dupont committed
33 34
#include <openssl/hmac.h>

35 36
typedef struct {
	HMAC_CTX *ctx;
37
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
38 39 40 41 42 43 44 45 46
	HMAC_CTX _ctx;
#endif
} isc_hmacsha_t;

typedef isc_hmacsha_t isc_hmacsha1_t;
typedef isc_hmacsha_t isc_hmacsha224_t;
typedef isc_hmacsha_t isc_hmacsha256_t;
typedef isc_hmacsha_t isc_hmacsha384_t;
typedef isc_hmacsha_t isc_hmacsha512_t;
Francis Dupont's avatar
Francis Dupont committed
47

Evan Hunt's avatar
Evan Hunt committed
48
#elif PKCS11CRYPTO
49
#include <pk11/pk11.h>
Evan Hunt's avatar
Evan Hunt committed
50

51 52 53 54 55
typedef pk11_context_t isc_hmacsha1_t;
typedef pk11_context_t isc_hmacsha224_t;
typedef pk11_context_t isc_hmacsha256_t;
typedef pk11_context_t isc_hmacsha384_t;
typedef pk11_context_t isc_hmacsha512_t;
Evan Hunt's avatar
Evan Hunt committed
56

Francis Dupont's avatar
Francis Dupont committed
57 58
#else

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
typedef struct {
	isc_sha1_t sha1ctx;
	unsigned char key[ISC_HMACSHA1_KEYLENGTH];
} isc_hmacsha1_t;

typedef struct {
	isc_sha224_t sha224ctx;
	unsigned char key[ISC_HMACSHA224_KEYLENGTH];
} isc_hmacsha224_t;

typedef struct {
	isc_sha256_t sha256ctx;
	unsigned char key[ISC_HMACSHA256_KEYLENGTH];
} isc_hmacsha256_t;

typedef struct {
	isc_sha384_t sha384ctx;
	unsigned char key[ISC_HMACSHA384_KEYLENGTH];
} isc_hmacsha384_t;

typedef struct {
	isc_sha512_t sha512ctx;
	unsigned char key[ISC_HMACSHA512_KEYLENGTH];
} isc_hmacsha512_t;
Francis Dupont's avatar
Francis Dupont committed
83
#endif
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

ISC_LANG_BEGINDECLS

void
isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
		  unsigned int len);

void
isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx);

void
isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
		    unsigned int len);

void
isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);

isc_boolean_t
isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);

104 105 106
isc_boolean_t
isc_hmacsha1_check(int testing);

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

void
isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
		    unsigned int len);

void
isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx);

void
isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
		      unsigned int len);

void
isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);

isc_boolean_t
isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);


void
isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
		    unsigned int len);

void
isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx);

void
isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
		      unsigned int len);

void
isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);

isc_boolean_t
isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);


void
isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
		    unsigned int len);

void
isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx);

void
isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
		      unsigned int len);

void
isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);

isc_boolean_t
isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);


void
isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
		    unsigned int len);

void
isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx);

void
isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
		      unsigned int len);

void
isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);

isc_boolean_t
isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);

ISC_LANG_ENDDECLS

#endif /* ISC_HMACSHA_H */