"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/hash_questions.c" between
dnsmasq-2.83.tar.xz and dnsmasq-2.84.tar.xz

About: Dnsmasq is a lightweight caching DNS forwarder and DHCP server.

hash_questions.c  (dnsmasq-2.83.tar.xz):hash_questions.c  (dnsmasq-2.84.tar.xz)
skipping to change at line 30 skipping to change at line 30
than CRC the raw bytes, since replies might be compressed differently. than CRC the raw bytes, since replies might be compressed differently.
We ignore case in the names for the same reason. We ignore case in the names for the same reason.
The hash used is SHA-256. If we're building with DNSSEC support, The hash used is SHA-256. If we're building with DNSSEC support,
we use the Nettle cypto library. If not, we prefer not to we use the Nettle cypto library. If not, we prefer not to
add a dependency on Nettle, and use a stand-alone implementaion. add a dependency on Nettle, and use a stand-alone implementaion.
*/ */
#include "dnsmasq.h" #include "dnsmasq.h"
#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH) #if defined(HAVE_DNSSEC) || defined(HAVE_CRYPTOHASH)
static const struct nettle_hash *hash;
static void *ctx;
static unsigned char *digest;
void hash_questions_init(void)
{
if (!(hash = hash_find("sha256")))
die(_("Failed to create SHA-256 hash object"), NULL, EC_MISC);
ctx = safe_malloc(hash->context_size);
digest = safe_malloc(hash->digest_size);
}
unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name ) unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name )
{ {
int q; int q;
unsigned char *p = (unsigned char *)(header+1); unsigned char *p = (unsigned char *)(header+1);
const struct nettle_hash *hash;
void *ctx;
unsigned char *digest;
if (!(hash = hash_find("sha256")) || !hash_init(hash, &ctx, &digest)) hash->init(ctx);
{
/* don't think this can ever happen. */
static unsigned char dummy[HASH_SIZE];
static int warned = 0;
if (!warned)
my_syslog(LOG_ERR, _("Failed to create SHA-256 hash object"));
warned = 1;
return dummy;
}
for (q = ntohs(header->qdcount); q != 0; q--) for (q = ntohs(header->qdcount); q != 0; q--)
{ {
char *cp, c; char *cp, c;
if (!extract_name(header, plen, &p, name, 1, 4)) if (!extract_name(header, plen, &p, name, 1, 4))
break; /* bad packet */ break; /* bad packet */
for (cp = name; (c = *cp); cp++) for (cp = name; (c = *cp); cp++)
if (c >= 'A' && c <= 'Z') if (c >= 'A' && c <= 'Z')
skipping to change at line 76 skipping to change at line 76
p += 4; p += 4;
if (!CHECK_LEN(header, p, plen, 0)) if (!CHECK_LEN(header, p, plen, 0))
break; /* bad packet */ break; /* bad packet */
} }
hash->digest(ctx, hash->digest_size, digest); hash->digest(ctx, hash->digest_size, digest);
return digest; return digest;
} }
#else /* HAVE_DNSSEC */ #else /* HAVE_DNSSEC || HAVE_CRYPTOHASH */
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest #define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
typedef unsigned char BYTE; // 8-bit byte typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16- bit machines typedef unsigned int WORD; // 32-bit word, change to "long" for 16- bit machines
typedef struct { typedef struct {
BYTE data[64]; BYTE data[64];
WORD datalen; WORD datalen;
unsigned long long bitlen; unsigned long long bitlen;
WORD state[8]; WORD state[8];
} SHA256_CTX; } SHA256_CTX;
static void sha256_init(SHA256_CTX *ctx); static void sha256_init(SHA256_CTX *ctx);
static void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len); static void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
static void sha256_final(SHA256_CTX *ctx, BYTE hash[]); static void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
void hash_questions_init(void)
{
}
unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name ) unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name )
{ {
int q; int q;
unsigned char *p = (unsigned char *)(header+1); unsigned char *p = (unsigned char *)(header+1);
SHA256_CTX ctx; SHA256_CTX ctx;
static BYTE digest[SHA256_BLOCK_SIZE]; static BYTE digest[SHA256_BLOCK_SIZE];
sha256_init(&ctx); sha256_init(&ctx);
for (q = ntohs(header->qdcount); q != 0; q--) for (q = ntohs(header->qdcount); q != 0; q--)
 End of changes. 5 change blocks. 
17 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)