bumped versions
[gnutls.git] / lib / gnutls_hash_int.h
blob5c55490e01b42a2ec64b465dcb47e3c8c36baaae
1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #ifndef GNUTLS_HASH_INT_H
24 #define GNUTLS_HASH_INT_H
26 #include <gnutls_int.h>
27 #include <gnutls/crypto.h>
28 #include <crypto-backend.h>
29 #include <crypto.h>
31 /* for message digests */
33 extern int crypto_mac_prio;
34 extern gnutls_crypto_mac_st _gnutls_mac_ops;
36 extern int crypto_digest_prio;
37 extern gnutls_crypto_digest_st _gnutls_digest_ops;
39 typedef int (*hash_func) (void *handle, const void *text, size_t size);
40 typedef void (*reset_func) (void *ctx);
41 typedef int (*output_func) (void *src_ctx, void *digest, size_t digestsize);
42 typedef void (*deinit_func) (void *handle);
44 typedef struct
46 gnutls_digest_algorithm_t algorithm;
47 const void *key;
48 int keysize;
50 hash_func hash;
51 reset_func reset;
52 output_func output;
53 deinit_func deinit;
55 void *handle;
56 } digest_hd_st;
58 /* basic functions */
59 int _gnutls_hmac_exists(gnutls_mac_algorithm_t algorithm);
60 int _gnutls_hmac_init (digest_hd_st *, gnutls_mac_algorithm_t algorithm,
61 const void *key, int keylen);
62 size_t _gnutls_hash_get_algo_len (gnutls_digest_algorithm_t algorithm);
63 #define _gnutls_hmac_get_algo_len(x) _gnutls_hash_get_algo_len((gnutls_digest_algorithm_t)x)
64 int _gnutls_hmac_fast (gnutls_mac_algorithm_t algorithm, const void *key,
65 int keylen, const void *text, size_t textlen,
66 void *digest);
68 inline static int
69 _gnutls_hmac (digest_hd_st * handle, const void *text, size_t textlen)
71 if (textlen > 0)
73 return handle->hash (handle->handle, text, textlen);
75 return 0;
78 inline static void
79 _gnutls_hmac_output (digest_hd_st * handle, void *digest)
81 size_t maclen;
83 maclen = _gnutls_hmac_get_algo_len (handle->algorithm);
85 if (digest != NULL)
87 handle->output (handle->handle, digest, maclen);
91 void
92 _gnutls_hmac_deinit (digest_hd_st * handle, void *digest);
94 inline static void
95 _gnutls_hmac_reset (digest_hd_st * handle)
97 if (handle->handle == NULL)
99 return;
102 handle->reset (handle->handle);
106 /* Hash interface */
107 int _gnutls_hash_init (digest_hd_st *, gnutls_digest_algorithm_t algorithm);
109 inline static int
110 _gnutls_hash (digest_hd_st * handle, const void *text, size_t textlen)
112 if (textlen > 0)
114 handle->hash (handle->handle, text, textlen);
116 return 0;
119 /* when the current output is needed without calling deinit
121 inline static void
122 _gnutls_hash_output (digest_hd_st * handle, void *digest)
124 size_t maclen;
126 maclen = _gnutls_hash_get_algo_len (handle->algorithm);
128 if (digest != NULL)
130 handle->output (handle->handle, digest, maclen);
134 inline static void
135 _gnutls_hash_reset (digest_hd_st * handle)
137 if (handle->handle == NULL)
139 return;
142 handle->reset (handle->handle);
145 void
146 _gnutls_hash_deinit (digest_hd_st * handle, void *digest);
149 _gnutls_hash_fast (gnutls_digest_algorithm_t algorithm,
150 const void *text, size_t textlen, void *digest);
152 /* help functions */
153 int _gnutls_mac_init_ssl3 (digest_hd_st *, gnutls_mac_algorithm_t algorithm,
154 void *key, int keylen);
155 int _gnutls_mac_deinit_ssl3 (digest_hd_st * handle, void *digest);
156 int _gnutls_mac_output_ssl3 (digest_hd_st * handle, void *digest);
158 int _gnutls_ssl3_generate_random (void *secret, int secret_len,
159 void *rnd, int random_len, int bytes,
160 uint8_t * ret);
161 int _gnutls_ssl3_hash_md5 (const void *first, int first_len,
162 const void *second, int second_len,
163 int ret_len, uint8_t * ret);
165 void _gnutls_mac_reset_ssl3 (digest_hd_st * handle);
167 int _gnutls_mac_deinit_ssl3_handshake (digest_hd_st * handle, void *digest,
168 uint8_t * key, uint32_t key_size);
170 inline static int IS_SHA(gnutls_digest_algorithm_t algo)
172 if (algo == GNUTLS_DIG_SHA1 || algo == GNUTLS_DIG_SHA224 ||
173 algo == GNUTLS_DIG_SHA256 || algo == GNUTLS_DIG_SHA384 ||
174 algo == GNUTLS_DIG_SHA512)
175 return 1;
176 return 0;
179 #endif /* GNUTLS_HASH_INT_H */