xref: /openbsd/usr.bin/dig/lib/isc/include/isc/hmacsha.h (revision 1fb015a8)
1 /*
2  * Copyright (C) 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.6 2020/09/14 08:40:44 florian 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/sha1.h>
28 #include <isc/sha2.h>
29 
30 #define ISC_HMACSHA1_KEYLENGTH ISC_SHA1_BLOCK_LENGTH
31 #define ISC_HMACSHA224_KEYLENGTH ISC_SHA224_BLOCK_LENGTH
32 #define ISC_HMACSHA256_KEYLENGTH ISC_SHA256_BLOCK_LENGTH
33 #define ISC_HMACSHA384_KEYLENGTH ISC_SHA384_BLOCK_LENGTH
34 #define ISC_HMACSHA512_KEYLENGTH ISC_SHA512_BLOCK_LENGTH
35 
36 #include <openssl/hmac.h>
37 
38 typedef struct {
39 	HMAC_CTX *ctx;
40 } isc_hmacsha_t;
41 
42 typedef isc_hmacsha_t isc_hmacsha1_t;
43 typedef isc_hmacsha_t isc_hmacsha224_t;
44 typedef isc_hmacsha_t isc_hmacsha256_t;
45 typedef isc_hmacsha_t isc_hmacsha384_t;
46 typedef isc_hmacsha_t isc_hmacsha512_t;
47 
48 void
49 isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
50 		  unsigned int len);
51 
52 void
53 isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx);
54 
55 void
56 isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
57 		    unsigned int len);
58 
59 void
60 isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);
61 
62 int
63 isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);
64 
65 void
66 isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
67 		    unsigned int len);
68 
69 void
70 isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx);
71 
72 void
73 isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
74 		      unsigned int len);
75 
76 void
77 isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);
78 
79 int
80 isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);
81 
82 void
83 isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
84 		    unsigned int len);
85 
86 void
87 isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx);
88 
89 void
90 isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
91 		      unsigned int len);
92 
93 void
94 isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);
95 
96 int
97 isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);
98 
99 void
100 isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
101 		    unsigned int len);
102 
103 void
104 isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx);
105 
106 void
107 isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
108 		      unsigned int len);
109 
110 void
111 isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);
112 
113 int
114 isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);
115 
116 void
117 isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
118 		    unsigned int len);
119 
120 void
121 isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx);
122 
123 void
124 isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
125 		      unsigned int len);
126 
127 void
128 isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);
129 
130 int
131 isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);
132 
133 #endif /* ISC_HMACSHA_H */
134