|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GNUTLS_LIB_HASH_INT_H
|
|
Packit Service |
4684c1 |
#define GNUTLS_LIB_HASH_INT_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include <gnutls/crypto.h>
|
|
Packit Service |
4684c1 |
#include <crypto-backend.h>
|
|
Packit Service |
4684c1 |
#include <crypto.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* for message digests */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
extern int crypto_mac_prio;
|
|
Packit Service |
4684c1 |
extern gnutls_crypto_mac_st _gnutls_mac_ops;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
extern int crypto_digest_prio;
|
|
Packit Service |
4684c1 |
extern gnutls_crypto_digest_st _gnutls_digest_ops;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef int (*hash_func) (void *handle, const void *text, size_t size);
|
|
Packit Service |
4684c1 |
typedef int (*nonce_func) (void *handle, const void *text, size_t size);
|
|
Packit Service |
4684c1 |
typedef int (*output_func) (void *src_ctx, void *digest,
|
|
Packit Service |
4684c1 |
size_t digestsize);
|
|
Packit Service |
4684c1 |
typedef void (*hash_deinit_func) (void *handle);
|
|
Packit Service |
4684c1 |
typedef void *(*copy_func) (const void *handle);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef struct {
|
|
Packit Service |
4684c1 |
const mac_entry_st *e;
|
|
Packit Service |
4684c1 |
hash_func hash;
|
|
Packit Service |
4684c1 |
output_func output;
|
|
Packit Service |
4684c1 |
hash_deinit_func deinit;
|
|
Packit Service |
4684c1 |
copy_func copy;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const void *key; /* esoteric use by SSL3 MAC functions */
|
|
Packit Service |
4684c1 |
int keysize;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void *handle;
|
|
Packit Service |
4684c1 |
} digest_hd_st;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef struct {
|
|
Packit Service |
4684c1 |
const mac_entry_st *e;
|
|
Packit Service |
4684c1 |
int mac_len;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
hash_func hash;
|
|
Packit Service |
4684c1 |
nonce_func setnonce;
|
|
Packit Service |
4684c1 |
output_func output;
|
|
Packit Service |
4684c1 |
hash_deinit_func deinit;
|
|
Packit Service |
4684c1 |
copy_func copy;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void *handle;
|
|
Packit Service |
4684c1 |
} mac_hd_st;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* basic functions */
|
|
Packit Service |
4684c1 |
int _gnutls_digest_exists(gnutls_digest_algorithm_t algo);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_mac_exists(gnutls_mac_algorithm_t algorithm);
|
|
Packit Service |
4684c1 |
int _gnutls_mac_init(mac_hd_st *, const mac_entry_st * e,
|
|
Packit Service |
4684c1 |
const void *key, int keylen);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_mac_copy(const mac_hd_st * handle, mac_hd_st * dst);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_mac_fast(gnutls_mac_algorithm_t algorithm, const void *key,
|
|
Packit Service |
4684c1 |
int keylen, const void *text, size_t textlen,
|
|
Packit Service |
4684c1 |
void *digest);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static int
|
|
Packit Service |
4684c1 |
_gnutls_mac(mac_hd_st * handle, const void *text, size_t textlen)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (textlen > 0) {
|
|
Packit Service |
4684c1 |
return handle->hash(handle->handle, text, textlen);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static void _gnutls_mac_output(mac_hd_st * handle, void *digest)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (digest != NULL) {
|
|
Packit Service |
4684c1 |
handle->output(handle->handle, digest, handle->mac_len);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static int
|
|
Packit Service |
4684c1 |
_gnutls_mac_set_nonce(mac_hd_st * handle, const void *nonce, size_t n_size)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (handle->setnonce)
|
|
Packit Service |
4684c1 |
return handle->setnonce(handle->handle, nonce, n_size);
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void _gnutls_mac_deinit(mac_hd_st * handle, void *digest);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Hash interface */
|
|
Packit Service |
4684c1 |
int _gnutls_hash_init(digest_hd_st *, const mac_entry_st * e);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static int
|
|
Packit Service |
4684c1 |
_gnutls_hash(digest_hd_st * handle, const void *text, size_t textlen)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (textlen > 0) {
|
|
Packit Service |
4684c1 |
return handle->hash(handle->handle, text, textlen);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* when the current output is needed without calling deinit
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
#define _gnutls_hash_output(h, d) \
|
|
Packit Service |
4684c1 |
(h)->output((h)->handle, d, _gnutls_hash_get_algo_len((h)->e))
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void _gnutls_hash_deinit(digest_hd_st * handle, void *digest);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_hash_copy(const digest_hd_st * handle, digest_hd_st * dst);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
_gnutls_hash_fast(gnutls_digest_algorithm_t algorithm,
|
|
Packit Service |
4684c1 |
const void *text, size_t textlen, void *digest);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef ENABLE_SSL3
|
|
Packit Service |
4684c1 |
/* helper functions */
|
|
Packit Service |
4684c1 |
int _gnutls_mac_init_ssl3(digest_hd_st *, const mac_entry_st * e,
|
|
Packit Service |
4684c1 |
void *key, int keylen);
|
|
Packit Service |
4684c1 |
int _gnutls_mac_deinit_ssl3(digest_hd_st * handle, void *digest);
|
|
Packit Service |
4684c1 |
int _gnutls_mac_output_ssl3(digest_hd_st * handle, void *digest);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_ssl3_generate_random(void *secret, int secret_len,
|
|
Packit Service |
4684c1 |
void *rnd, int random_len, int bytes,
|
|
Packit Service |
4684c1 |
uint8_t * ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_mac_deinit_ssl3_handshake(digest_hd_st * handle, void *digest,
|
|
Packit Service |
4684c1 |
uint8_t * key, uint32_t key_size);
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static int IS_SHA(gnutls_digest_algorithm_t algo)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (algo == GNUTLS_DIG_SHA1 || algo == GNUTLS_DIG_SHA224 ||
|
|
Packit Service |
4684c1 |
algo == GNUTLS_DIG_SHA256 || algo == GNUTLS_DIG_SHA384 ||
|
|
Packit Service |
4684c1 |
algo == GNUTLS_DIG_SHA512)
|
|
Packit Service |
4684c1 |
return 1;
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* GNUTLS_LIB_HASH_INT_H */
|