Fixes for cross compiling

This commit is contained in:
Willem Toorop 2016-01-07 15:32:23 +01:00
parent fa1fa55110
commit cf387ca3f2
6 changed files with 45 additions and 56 deletions

View File

@ -1019,14 +1019,25 @@ AC_SUBST(C99COMPATFLAGS)
AH_BOTTOM([ AH_BOTTOM([
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
/* the version of the windows API enabled */ /* the version of the windows API enabled */
#undef WINVER #ifndef WINVER
#undef _WIN32_WINNT
#define WINVER 0x0600 // 0x0502 #define WINVER 0x0600 // 0x0502
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600 // 0x0502 #define _WIN32_WINNT 0x0600 // 0x0502
#endif
#ifdef HAVE_WINSOCK2_H #ifdef HAVE_WINSOCK2_H
#include <winsock2.h> #include <winsock2.h>
#include<BaseTsd.h>
#endif #endif
#ifdef HAVE_WS2TCPIP_H #ifdef HAVE_WS2TCPIP_H
@ -1047,15 +1058,6 @@ AH_BOTTOM([
#endif #endif
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -26,7 +26,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <signal.h> #include <signal.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -35,40 +37,6 @@
#include <sys/time.h> #include <sys/time.h>
#ifndef GETDNS_ON_WINDOWS #ifndef GETDNS_ON_WINDOWS
#include <sys/mman.h> #include <sys/mman.h>
#else
#include <wincrypt.h>
#include <process.h>
int getentropy(void *buf, size_t len);
/*
* On Windows, CryptGenRandom is supposed to be a well-seeded
* cryptographically strong random number generator.
*/
int
getentropy(void *buf, size_t len)
{
HCRYPTPROV provider;
if (len > 256) {
errno = EIO;
return -1;
}
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT) == 0)
goto fail;
if (CryptGenRandom(provider, len, buf) == 0) {
CryptReleaseContext(provider, 0);
goto fail;
}
CryptReleaseContext(provider, 0);
return (0);
fail:
errno = EIO;
return (-1);
}
#endif #endif
#define KEYSTREAM_ONLY #define KEYSTREAM_ONLY

View File

@ -16,10 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "config.h" #include "config.h"
#ifndef GETDNS_ON_WINDOWS
/* /*
#define _POSIX_C_SOURCE 199309L #define _POSIX_C_SOURCE 199309L
@ -49,7 +46,12 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#if defined(HAVE_SSL)
#include <openssl/sha.h> #include <openssl/sha.h>
#elif defined(HAVE_NETTLE)
#include <nettle/sha.h>
#endif
#include <linux/types.h> #include <linux/types.h>
#include <linux/random.h> #include <linux/random.h>
@ -70,9 +72,21 @@
HD(b); \ HD(b); \
} while (0) } while (0)
#if defined(HAVE_SSL)
#define CRYPTO_SHA512_CTX SHA512_CTX
#define CRYPTO_SHA512_INIT(x) SHA512_Init(x)
#define CRYPTO_SHA512_FINAL(r, c) SHA512_Final(r, c)
#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) #define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*))) #define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
#elif defined(HAVE_NETTLE)
#define CRYPTO_SHA512_CTX struct sha512_ctx
#define CRYPTO_SHA512_INIT(x) sha512_init(x)
#define CRYPTO_SHA512_FINAL(r, c) sha512_digest(c, SHA512_DIGEST_SIZE, r)
#define HR(x, l) (sha512_update(&ctx, (l), (uint8_t *)(x)))
#define HD(x) (sha512_update(&ctx, sizeof (x), (uint8_t *)&(x)))
#define HF(x) (sha512_update(&ctx, sizeof (void*), (uint8_t *)&(x)))
#endif
int getentropy(void *buf, size_t len); int getentropy(void *buf, size_t len);
@ -125,7 +139,7 @@ getentropy(void *buf, size_t len)
* Try to use sysctl CTL_KERN, KERN_RANDOM, RANDOM_UUID. * Try to use sysctl CTL_KERN, KERN_RANDOM, RANDOM_UUID.
* sysctl is a failsafe API, so it guarantees a result. This * sysctl is a failsafe API, so it guarantees a result. This
* should work inside a chroot, or when file descriptors are * should work inside a chroot, or when file descriptors are
* exhuasted. * exhausted.
* *
* However this can fail if the Linux kernel removes support * However this can fail if the Linux kernel removes support
* for sysctl. Starting in 2007, there have been efforts to * for sysctl. Starting in 2007, there have been efforts to
@ -340,7 +354,7 @@ getentropy_fallback(void *buf, size_t len)
struct rusage ru; struct rusage ru;
sigset_t sigset; sigset_t sigset;
struct stat st; struct stat st;
SHA512_CTX ctx; CRYPTO_SHA512_CTX ctx;
static pid_t lastpid; static pid_t lastpid;
pid_t pid; pid_t pid;
size_t i, ii, m; size_t i, ii, m;
@ -357,7 +371,7 @@ getentropy_fallback(void *buf, size_t len)
} }
for (i = 0; i < len; ) { for (i = 0; i < len; ) {
int j; int j;
SHA512_Init(&ctx); CRYPTO_SHA512_INIT(&ctx);
for (j = 0; j < repeat; j++) { for (j = 0; j < repeat; j++) {
HX((e = gettimeofday(&tv, NULL)) == -1, tv); HX((e = gettimeofday(&tv, NULL)) == -1, tv);
if (e != -1) { if (e != -1) {
@ -529,7 +543,7 @@ getentropy_fallback(void *buf, size_t len)
# endif # endif
#endif /* HAVE_GETAUXVAL */ #endif /* HAVE_GETAUXVAL */
SHA512_Final(results, &ctx); CRYPTO_SHA512_FINAL(results, &ctx);
memcpy((char*)buf + i, results, min(sizeof(results), len - i)); memcpy((char*)buf + i, results, min(sizeof(results), len - i));
i += min(sizeof(results), len - i); i += min(sizeof(results), len - i);
} }
@ -541,4 +555,3 @@ getentropy_fallback(void *buf, size_t len)
errno = EIO; errno = EIO;
return -1; return -1;
} }
#endif

View File

@ -30,7 +30,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <termios.h> #include <termios.h>
#include <fcntl.h> #include <fcntl.h>
@ -39,10 +41,14 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#ifdef HAVE_SYS_SHA2_H
#include <sys/sha2.h> #include <sys/sha2.h>
#define SHA512_Init SHA512Init #define SHA512_Init SHA512Init
#define SHA512_Update SHA512Update #define SHA512_Update SHA512Update
#define SHA512_Final SHA512Final #define SHA512_Final SHA512Final
#else
#include "openssl/sha.h"
#endif
#include <sys/vfs.h> #include <sys/vfs.h>
#include <sys/statfs.h> #include <sys/statfs.h>

View File

@ -70,7 +70,7 @@ unsigned char *SHA512(void *data, unsigned int data_len, unsigned char *digest);
* Please make sure that your system defines BYTE_ORDER. If your * Please make sure that your system defines BYTE_ORDER. If your
* architecture is little-endian, make sure it also defines * architecture is little-endian, make sure it also defines
* LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
* equivilent. * equivalent.
* *
* If your system does not define the above, then you can do so by * If your system does not define the above, then you can do so by
* hand like this: * hand like this:

View File

@ -271,7 +271,7 @@ _getdns_rr_iter2rr_dict(struct mem_funcs *mf, _getdns_rr_iter *i)
} else if (rdf->rdd_pos->type == GETDNS_RDF_SPECIAL) } else if (rdf->rdd_pos->type == GETDNS_RDF_SPECIAL)
val_type = wf_special; val_type = wf_special;
else else
assert(0); assert(((val_type = wf_int), 0));
if (! rdf->rdd_repeat) { if (! rdf->rdd_repeat) {
switch (val_type) { switch (val_type) {