Coverage Report

Created: 2023-03-26 07:33

/src/gnutls/lib/fingerprint.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
3
 *
4
 * Author: Nikos Mavrogiannopoulos
5
 *
6
 * This file is part of GnuTLS.
7
 *
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 2.1 of
11
 * the License, or (at your option) any later version.
12
 *
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.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
20
 *
21
 */
22
23
#include "gnutls_int.h"
24
#include <auth/srp_kx.h>
25
#include <auth/anon.h>
26
#include <auth/cert.h>
27
#include <auth/psk.h>
28
#include "errors.h"
29
#include <auth.h>
30
#include <state.h>
31
#include <datum.h>
32
#include <algorithms.h>
33
34
/**
35
 * gnutls_fingerprint:
36
 * @algo: is a digest algorithm
37
 * @data: is the data
38
 * @result: is the place where the result will be copied (may be null).
39
 * @result_size: should hold the size of the result. The actual size
40
 * of the returned result will also be copied there.
41
 *
42
 * This function will calculate a fingerprint (actually a hash), of
43
 * the given data.  The result is not printable data.  You should
44
 * convert it to hex, or to something else printable.
45
 *
46
 * This is the usual way to calculate a fingerprint of an X.509 DER
47
 * encoded certificate.  Note however that the fingerprint of an
48
 * OpenPGP certificate is not just a hash and cannot be calculated with this
49
 * function.
50
 *
51
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
52
 *   an error code is returned.
53
 **/
54
int
55
gnutls_fingerprint(gnutls_digest_algorithm_t algo,
56
       const gnutls_datum_t * data, void *result,
57
       size_t *result_size)
58
0
{
59
0
  int ret;
60
0
  int hash_len = _gnutls_hash_get_algo_len(hash_to_entry(algo));
61
62
0
  if (hash_len < 0 || (unsigned)hash_len > *result_size || result == NULL) {
63
0
    *result_size = hash_len;
64
0
    return GNUTLS_E_SHORT_MEMORY_BUFFER;
65
0
  }
66
0
  *result_size = hash_len;
67
68
0
  if (result) {
69
0
    ret = _gnutls_hash_fast(algo, data->data, data->size, result);
70
0
    if (ret < 0)
71
0
      return gnutls_assert_val(ret);
72
0
  }
73
74
0
  return 0;
75
0
}