merged with origin/1.1

This commit is contained in:
thorkill 2015-07-17 00:29:46 +02:00
commit b68eaa7ce4
7 changed files with 19 additions and 26 deletions

View file

@ -9,6 +9,7 @@ AM_INIT_AUTOMAKE([std-options subdir-objects -Wall])
AC_CONFIG_HEADERS([config.h])
AM_PROG_AR
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
# Enable GNU extensions.
# Define this here, not in acconfig's @TOP@ section, since definitions

View file

@ -1,8 +0,0 @@
These files are used by a program called aclocal (part of the GNU automake
package). aclocal uses these files to create aclocal.m4 which is in turn
used by autoconf to create the configure script at the the top level in
this distribution.
The Makefile.am file in this directory is automatically generated
from the template file, Makefile.am.in. The generation will fail
if you don't have all the right tools.

View file

@ -29,7 +29,7 @@ static uint32_t hash_function(const void *p, size_t len) {
uint32_t hash = 0;
while(true) {
for(int i = len > 4 ? 4 : len; --i;)
hash += q[len - i] << (8 * i);
hash += (uint32_t)q[len - i] << (8 * i);
hash *= 0x9e370001UL; // Golden ratio prime.
if(len <= 4)
break;

View file

@ -28,36 +28,38 @@ static void memxor(char *buf, char c, size_t len) {
}
static const size_t mdlen = 64;
static const size_t blklen = 128;
static bool hmac_sha512(const char *key, size_t keylen, const char *msg, size_t msglen, char *out) {
char tmp[2 * mdlen];
char tmp[blklen + mdlen];
sha512_context md;
if(keylen <= mdlen) {
if(keylen <= blklen) {
memcpy(tmp, key, keylen);
memset(tmp + keylen, 0, mdlen - keylen);
memset(tmp + keylen, 0, blklen - keylen);
} else {
if(sha512(key, keylen, tmp) != 0)
return false;
memset(tmp + mdlen, 0, blklen - mdlen);
}
if(sha512_init(&md) != 0)
return false;
// ipad
memxor(tmp, 0x36, mdlen);
if(sha512_update(&md, tmp, mdlen) != 0)
memxor(tmp, 0x36, blklen);
if(sha512_update(&md, tmp, blklen) != 0)
return false;
// message
if(sha512_update(&md, msg, msglen) != 0)
return false;
if(sha512_final(&md, tmp + mdlen) != 0)
if(sha512_final(&md, tmp + blklen) != 0)
return false;
// opad
memxor(tmp, 0x36 ^ 0x5c, mdlen);
memxor(tmp, 0x36 ^ 0x5c, blklen);
if(sha512(tmp, sizeof tmp, out) != 0)
return false;
@ -82,17 +84,17 @@ bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char
while(outlen > 0) {
/* Inner HMAC */
if(!hmac_sha512(data, sizeof data, secret, secretlen, data))
if(!hmac_sha512(secret, secretlen, data, sizeof data, data))
return false;
/* Outer HMAC */
if(outlen >= mdlen) {
if(!hmac_sha512(data, sizeof data, secret, secretlen, out))
if(!hmac_sha512(secret, secretlen, data, sizeof data, out))
return false;
out += mdlen;
outlen -= mdlen;
} else {
if(!hmac_sha512(data, sizeof data, secret, secretlen, hash))
if(!hmac_sha512(secret, secretlen, data, sizeof data, hash))
return false;
memcpy(out, hash, outlen);
out += outlen;

View file

@ -190,6 +190,7 @@ bool add_edge_h(connection_t *c, const char *request) {
} else {
logger(DEBUG_PROTOCOL, LOG_WARNING, "%s:%d %s -> %s - got edge we know from older version? (%d.%d)",
__FUNCTION__, __LINE__, e->from->name, e->to->name, c->protocol_major, c->protocol_minor);
sockaddrfree(&local_address);
return true;
}
} else {

View file

@ -40,9 +40,9 @@ splay_tree_t *subnet_tree;
/* Subnet lookup cache */
hash_t *ipv4_cache;
hash_t *ipv6_cache;
hash_t *mac_cache;
static hash_t *ipv4_cache;
static hash_t *ipv6_cache;
static hash_t *mac_cache;
void subnet_cache_flush(void) {
hash_clear(ipv4_cache);

View file

@ -401,11 +401,8 @@ bool net2str(char *netstr, int len, const subnet_t *subnet) {
len -= result;
}
if (subnet->weight != DEFAULT_WEIGHT) {
if (subnet->weight != DEFAULT_WEIGHT)
snprintf(netstr, len, "#%d", subnet->weight);
netstr += result;
len -= result;
}
return true;
}