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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*!
* \file nsec3.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
* \author Jan Vcelak <jan.vcelak@nic.cz>
*
* \brief Functions for computation of NSEC3 hashes.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _KNOT_DNSSEC_NSEC3_H_
#define _KNOT_DNSSEC_NSEC3_H_
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "libknot/consts.h"
#include "libknot/rrset.h"
/*---------------------------------------------------------------------------*/
/*!
* \brief Get length of the raw NSEC3 hash.
*
* \param algorithm NSEC3 hash algorithm.
*
* \return Length of the hash, 0 for unknown hash algorithm.
*/
inline static size_t knot_nsec3_hash_length(uint8_t algorithm)
{
if (algorithm == KNOT_NSEC3_ALGORITHM_SHA1) {
return 20;
} else {
return 0;
}
}
/*!
* \brief Get length of the NSEC3 hash encoded in Base32 encoding.
*
* \param algorithm NSEC3 hash algorithm.
*
* \return Length of the hash, 0 for unknown hash algorithm.
*/
inline static size_t knot_nsec3_hash_b32_length(uint8_t algorithm)
{
if (algorithm == KNOT_NSEC3_ALGORITHM_SHA1) {
return 32;
} else {
return 0;
}
}
/*---------------------------------------------------------------------------*/
/*!
* \brief Structure representing the NSEC3PARAM resource record.
*/
typedef struct {
uint8_t algorithm; //!< Hash algorithm.
uint8_t flags; //!< Flags.
uint16_t iterations; //!< Additional iterations of the hash function.
uint8_t salt_length; //!< Length of the salt field in bytes.
uint8_t *salt; //!< Salt used in hashing.
} knot_nsec3_params_t;
/*---------------------------------------------------------------------------*/
/*!
* \brief Initialize the structure with NSEC3 params from NSEC3PARAM RR set.
*
* \param params Structure to initialize.
* \param nsec3param The NSEC3PARAM RR set.
*
* \return Error code, KNOT_EOK on success.
*/
int knot_nsec3_params_from_wire(knot_nsec3_params_t *params,
const knot_rrset_t *rrset);
/*!
* \brief Clean up structure with NSEC3 params (do not deallocate).
*
* \param params Structure with NSEC3 params.
*/
void knot_nsec3_params_free(knot_nsec3_params_t *params);
/*!
* \brief Compute NSEC3 hash for given data.
*
* \param[in] params NSEC3 parameters.
* \param[in] data Data to compute hash for.
* \param[in] size Size of the data.
* \param[out] digest Computed hash.
* \param[out] digest_size Size of the computed hash.
*
* \return Error code, KNOT_EOK if successful.
*/
int knot_nsec3_hash(const knot_nsec3_params_t *params, const uint8_t *data,
size_t size, uint8_t **digest, size_t *digest_size);
#endif // _KNOT_DNSSEC_NSEC3_H_
/*! @} */
|