Line data Source code
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 1597 : gnutls_fingerprint(gnutls_digest_algorithm_t algo, 56 : const gnutls_datum_t * data, void *result, 57 : size_t * result_size) 58 : { 59 1597 : int ret; 60 1597 : int hash_len = _gnutls_hash_get_algo_len(hash_to_entry(algo)); 61 : 62 1597 : if (hash_len < 0 || (unsigned) hash_len > *result_size 63 1597 : || result == NULL) { 64 0 : *result_size = hash_len; 65 0 : return GNUTLS_E_SHORT_MEMORY_BUFFER; 66 : } 67 1597 : *result_size = hash_len; 68 : 69 1597 : if (result) { 70 1597 : ret = 71 1597 : _gnutls_hash_fast(algo, data->data, data->size, 72 : result); 73 1597 : if (ret < 0) 74 0 : return gnutls_assert_val(ret); 75 : } 76 : 77 : return 0; 78 : } 79 : 80 :