Blame lib/fingerprint.c

Packit Service 4684c1
/*
Packit Service 4684c1
 * Copyright (C) 2001-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
#include "gnutls_int.h"
Packit Service 4684c1
#include <auth/srp_kx.h>
Packit Service 4684c1
#include <auth/anon.h>
Packit Service 4684c1
#include <auth/cert.h>
Packit Service 4684c1
#include <auth/psk.h>
Packit Service 4684c1
#include "errors.h"
Packit Service 4684c1
#include <auth.h>
Packit Service 4684c1
#include <state.h>
Packit Service 4684c1
#include <datum.h>
Packit Service 4684c1
#include <algorithms.h>
Packit Service 4684c1
Packit Service 4684c1
/**
Packit Service 4684c1
 * gnutls_fingerprint:
Packit Service 4684c1
 * @algo: is a digest algorithm
Packit Service 4684c1
 * @data: is the data
Packit Service 4684c1
 * @result: is the place where the result will be copied (may be null).
Packit Service 4684c1
 * @result_size: should hold the size of the result. The actual size
Packit Service 4684c1
 * of the returned result will also be copied there.
Packit Service 4684c1
 *
Packit Service 4684c1
 * This function will calculate a fingerprint (actually a hash), of
Packit Service 4684c1
 * the given data.  The result is not printable data.  You should
Packit Service 4684c1
 * convert it to hex, or to something else printable.
Packit Service 4684c1
 *
Packit Service 4684c1
 * This is the usual way to calculate a fingerprint of an X.509 DER
Packit Service 4684c1
 * encoded certificate.  Note however that the fingerprint of an
Packit Service 4684c1
 * OpenPGP certificate is not just a hash and cannot be calculated with this
Packit Service 4684c1
 * function.
Packit Service 4684c1
 *
Packit Service 4684c1
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
Packit Service 4684c1
 *   an error code is returned.
Packit Service 4684c1
 **/
Packit Service 4684c1
int
Packit Service 4684c1
gnutls_fingerprint(gnutls_digest_algorithm_t algo,
Packit Service 4684c1
		   const gnutls_datum_t * data, void *result,
Packit Service 4684c1
		   size_t * result_size)
Packit Service 4684c1
{
Packit Service 4684c1
	int ret;
Packit Service 4684c1
	int hash_len = _gnutls_hash_get_algo_len(hash_to_entry(algo));
Packit Service 4684c1
Packit Service 4684c1
	if (hash_len < 0 || (unsigned) hash_len > *result_size
Packit Service 4684c1
	    || result == NULL) {
Packit Service 4684c1
		*result_size = hash_len;
Packit Service 4684c1
		return GNUTLS_E_SHORT_MEMORY_BUFFER;
Packit Service 4684c1
	}
Packit Service 4684c1
	*result_size = hash_len;
Packit Service 4684c1
Packit Service 4684c1
	if (result) {
Packit Service 4684c1
		ret =
Packit Service 4684c1
		    _gnutls_hash_fast(algo, data->data, data->size,
Packit Service 4684c1
				      result);
Packit Service 4684c1
		if (ret < 0)
Packit Service 4684c1
			return gnutls_assert_val(ret);
Packit Service 4684c1
	}
Packit Service 4684c1
Packit Service 4684c1
	return 0;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1