Skip to content
Snippets Groups Projects
Commit 77c1c5f5 authored by Lubos Slovak's avatar Lubos Slovak
Browse files

NSEC3 error codes + documentation.

refs #644, #646
parent 3c45a575
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,8 @@ static const dnslib_lookup_table_t dnslib_error_msgs[] = {
{DNSLIB_EBADARG, "Wrong argument supported."},
{DNSLIB_EFEWDATA, "Not enough data to parse."},
{DNSLIB_ESPACE, "Not enough space provided."},
{DNSLIB_EMALF, "Malformed data."}
{DNSLIB_EMALF, "Malformed data."},
{DNSLIB_ECRYPTO, "Error in crypto library."}
};
/*----------------------------------------------------------------------------*/
......
......@@ -18,7 +18,8 @@ enum dnslib_error {
DNSLIB_EBADARG,
DNSLIB_EFEWDATA,
DNSLIB_ESPACE,
DNSLIB_EMALF
DNSLIB_EMALF,
DNSLIB_ECRYPTO
};
typedef enum dnslib_error dnslib_error_t;
......
......@@ -11,6 +11,7 @@
#include "dnslib/descriptor.h"
#include "dnslib/utils.h"
#include "dnslib/tolower.h"
#include "dnslib/error.h"
/*----------------------------------------------------------------------------*/
......@@ -56,7 +57,7 @@ int dnslib_nsec3_params_from_wire(dnslib_nsec3_params_t *params,
debug_dnslib_nsec3("none\n");
}
return 0;
return DNSLIB_EOK;
}
static uint8_t *dnslib_nsec3_to_lowercase(const uint8_t *data, size_t size)
......@@ -77,11 +78,8 @@ int dnslib_nsec3_sha1(const dnslib_nsec3_params_t *params,
const uint8_t *data, size_t size, uint8_t **digest,
size_t *digest_size)
{
assert(digest != NULL);
assert(digest_size != NULL);
if (data == NULL) {
return -3;
if (digest == NULL || digest_size == NULL || data == NULL) {
return DNSLIB_EBADARG;
}
uint8_t *salt = params->salt;
......@@ -161,11 +159,8 @@ int dnslib_nsec3_sha1(const dnslib_nsec3_params_t *params,
const uint8_t *data, size_t size, uint8_t **digest,
size_t *digest_size)
{
assert(digest != NULL);
assert(digest_size != NULL);
if (data == NULL) {
return -3;
if (digest == NULL || digest_size == NULL || data == NULL) {
return DNSLIB_EBADARG;
}
uint8_t *salt = params->salt;
......@@ -190,13 +185,13 @@ int dnslib_nsec3_sha1(const dnslib_nsec3_params_t *params,
*digest = (uint8_t *)malloc(SHA_DIGEST_LENGTH);
if (*digest == NULL) {
ERR_ALLOC_FAILED;
return -1;
return DNSLIB_ENOMEM;
}
uint8_t *data_low = dnslib_nsec3_to_lowercase(data, size);
if (data_low == NULL) {
free(*digest);
return -1;
return DNSLIB_ENOMEM;
}
const uint8_t *in = data_low;
......@@ -239,7 +234,7 @@ int dnslib_nsec3_sha1(const dnslib_nsec3_params_t *params,
debug_dnslib_nsec3("Error calculating SHA-1 hash.\n");
free(data_low);
free(*digest);
return -2;
return DNSLIB_ECRYPTO;
}
}
......@@ -253,7 +248,7 @@ int dnslib_nsec3_sha1(const dnslib_nsec3_params_t *params,
debug_dnslib_nsec3("\n");
free(data_low);
return 0;
return DNSLIB_EOK;
}
#endif
......
......@@ -20,25 +20,53 @@
#define DNSLIB_NSEC3_SHA_USE_EVP 0
/*----------------------------------------------------------------------------*/
/*!
* \brief Structure representing the NSEC3PARAM resource record.
*/
struct dnslib_nsec3_params {
uint8_t algorithm;
uint8_t flags;
uint16_t iterations;
uint8_t salt_length;
uint8_t *salt;
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. */
};
typedef struct dnslib_nsec3_params dnslib_nsec3_params_t;
/*----------------------------------------------------------------------------*/
/*!
* \param Initializes the NSEC3PARAM structure.
*
* \param params NSEC3PARAM structure to initialize.
* \param nsec3param The NSEC3PARAM RRset.
*
* \retval DNSLIB_EOK on success (always).
*/
int dnslib_nsec3_params_from_wire(dnslib_nsec3_params_t *params,
const dnslib_rrset_t *nsec3param);
/*!
* \brief Hashes the given data using the SHA1 hash and the given parameters.
*
* \param[in] params NSEC3PARAM structure with the required parameters for
* hashing.
* \param[in] data Data to hash.
* \param[in] size Size of the data in bytes.
* \param[out] digest Result will be store here.
* \param[out] digest_size Size of the result in octets will be stored here.
*
* \retval DNSLIB_EOK if successful.
* \retval DNSLIB_EBADARG
* \retval DNSLIB_ECRYPTO
*/
int dnslib_nsec3_sha1(const dnslib_nsec3_params_t *params, const uint8_t *data,
size_t size, uint8_t **digest, size_t *digest_size);
/*!
* \brief Properly cleans up (but does not deallocate) the NSEC3PARAM structure.
*
* \param params NSEC3PARAMS structure to clean up.
*/
void dnslib_nsec3_params_free(dnslib_nsec3_params_t *params);
/*----------------------------------------------------------------------------*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment