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>
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
);
46 gnutls_digest_algorithm_t algorithm
;
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
,
69 _gnutls_hmac (digest_hd_st
* handle
, const void *text
, size_t textlen
)
73 return handle
->hash (handle
->handle
, text
, textlen
);
79 _gnutls_hmac_output (digest_hd_st
* handle
, void *digest
)
83 maclen
= _gnutls_hmac_get_algo_len (handle
->algorithm
);
87 handle
->output (handle
->handle
, digest
, maclen
);
92 _gnutls_hmac_deinit (digest_hd_st
* handle
, void *digest
);
95 _gnutls_hmac_reset (digest_hd_st
* handle
)
97 if (handle
->handle
== NULL
)
102 handle
->reset (handle
->handle
);
107 int _gnutls_hash_init (digest_hd_st
*, gnutls_digest_algorithm_t algorithm
);
110 _gnutls_hash (digest_hd_st
* handle
, const void *text
, size_t textlen
)
114 handle
->hash (handle
->handle
, text
, textlen
);
119 /* when the current output is needed without calling deinit
122 _gnutls_hash_output (digest_hd_st
* handle
, void *digest
)
126 maclen
= _gnutls_hash_get_algo_len (handle
->algorithm
);
130 handle
->output (handle
->handle
, digest
, maclen
);
135 _gnutls_hash_reset (digest_hd_st
* handle
)
137 if (handle
->handle
== NULL
)
142 handle
->reset (handle
->handle
);
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
);
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
,
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
)
179 #endif /* GNUTLS_HASH_INT_H */