summaryrefslogtreecommitdiffstats
path: root/src/libdnssec/digest.h
blob: 76709aa534f7c8cd55b276c85ad2fac10de3a667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*  Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/*!
 * \file
 *
 * \addtogroup digest
 *
 * \brief Data hashing operations.
 *
 * @{
 */

#pragma once

#include "libdnssec/binary.h"
#include "libdnssec/error.h"

typedef enum {
	DNSSEC_DIGEST_INVALID = 0,
	DNSSEC_DIGEST_SHA384  = 1,
	DNSSEC_DIGEST_SHA512  = 2,
} dnssec_digest_t;

struct dnssec_digest_ctx;
typedef struct dnssec_digest_ctx dnssec_digest_ctx_t;

/*!
 * \brief Initialize digest context.
 *
 * \param algorithm   Hasing algorithm to be used.
 * \param out_ctx     Output: context structure to be initialized.
 *
 * \return DNSSEC_E*
 */
int dnssec_digest_init(dnssec_digest_t algorithm, dnssec_digest_ctx_t **out_ctx);

/*!
 * \brief Digest data.
 *
 * \param ctx    Digest context.
 * \param data   Data to be hashed.
 *
 * \note This function may be invoked repeatedly for single digest context,
 *       hashing all data as concatenated.
 *
 * \return DNSSEC_E*
 *
 * \note If error is returned, the digest context is automatically disposed.
 */
int dnssec_digest(dnssec_digest_ctx_t *ctx, dnssec_binary_t *data);

/*!
 * \brief Finalize digest, dispose digest context and return the hash.
 *
 * \param ctx   Digest context.
 * \param out   Output: computed hash.
 *
 * \return DNSSEC_E*
 */
int dnssec_digest_finish(dnssec_digest_ctx_t *ctx, dnssec_binary_t *out);

/*! @} */