diff --git a/crypto/crypto_misc.c b/crypto/crypto_misc.c index 621b1f6dc..bf51cbc75 100644 --- a/crypto/crypto_misc.c +++ b/crypto/crypto_misc.c @@ -109,7 +109,7 @@ int get_file(const char *filename, uint8_t **buf) EXP_FUNC void STDCALL RNG_initialize() { #if !defined(WIN32) && defined(CONFIG_USE_DEV_URANDOM) - rng_fd = ax_open("/dev/urandom", O_RDONLY); + rng_fd = open("/dev/urandom", O_RDONLY); #elif defined(WIN32) && defined(CONFIG_WIN32_USE_CRYPTO_LIB) if (!CryptAcquireContext(&gCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) @@ -130,7 +130,7 @@ EXP_FUNC void STDCALL RNG_initialize() /* start of with a stack to copy across */ int i; memcpy(entropy_pool, &i, ENTROPY_POOL_SIZE); - srand((unsigned int)&i); + rand_r((unsigned int *)entropy_pool); #endif } @@ -181,7 +181,7 @@ EXP_FUNC int STDCALL get_random(int num_rand_bytes, uint8_t *rand_data) #else /* nothing else to use, so use a custom RNG */ /* The method we use when we've got nothing better. Use RC4, time and a couple of random seeds to generate a random sequence */ - RC4_CTX rng_ctx; + AES_CTX rng_ctx; struct timeval tv; MD5_CTX rng_digest_ctx; uint8_t digest[MD5_SIZE]; @@ -200,10 +200,10 @@ EXP_FUNC int STDCALL get_random(int num_rand_bytes, uint8_t *rand_data) MD5_Final(digest, &rng_digest_ctx); /* come up with the random sequence */ - RC4_setup(&rng_ctx, digest, MD5_SIZE); /* use as a key */ + AES_set_key(&rng_ctx, digest, (const uint8_t *)ep, AES_MODE_128); /* use as a key */ memcpy(rand_data, entropy_pool, num_rand_bytes < ENTROPY_POOL_SIZE ? num_rand_bytes : ENTROPY_POOL_SIZE); - RC4_crypt(&rng_ctx, rand_data, rand_data, num_rand_bytes); + AES_cbc_encrypt(&rng_ctx, rand_data, rand_data, num_rand_bytes); /* move things along */ for (i = ENTROPY_POOL_SIZE-1; i >= MD5_SIZE ; i--) diff --git a/ssl/os_port.c b/ssl/os_port.c index b8a2b19a8..060bc073a 100644 --- a/ssl/os_port.c +++ b/ssl/os_port.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 2007, Cameron Rich - * + * Copyright (c) 2007-2016, Cameron Rich + * * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -91,9 +91,3 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size) } #endif -#undef malloc -#undef realloc -#undef calloc - -static const char * out_of_mem_str = "out of memory"; -static const char * file_open_str = "Could not open file \"%s\""; diff --git a/ssl/os_port.h b/ssl/os_port.h index 791c10af2..196293809 100644 --- a/ssl/os_port.h +++ b/ssl/os_port.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2015, Cameron Rich + * Copyright (c) 2007-2016, Cameron Rich * * All rights reserved. * @@ -189,27 +189,7 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size); #endif /* Not Win32 */ /* some functions to mutate the way these work */ -#define malloc(A) ax_port_malloc(A, __FILE__, __LINE__) -#ifndef realloc -#define realloc(A,B) ax_port_realloc(A,B, __FILE__, __LINE__) -#endif -#define calloc(A,B) ax_port_calloc(A,B, __FILE__, __LINE__) -#define free(x) ax_port_free(x) - -EXP_FUNC void * STDCALL ax_port_malloc(size_t s, const char*, int); -EXP_FUNC void * STDCALL ax_port_realloc(void *y, size_t s, const char*, int); -EXP_FUNC void * STDCALL ax_port_calloc(size_t n, size_t s, const char*, int); -EXP_FUNC void * STDCALL ax_port_free(void*); -EXP_FUNC int STDCALL ax_open(const char *pathname, int flags); - -inline uint32_t htonl(uint32_t n){ - return ((n & 0xff) << 24) | - ((n & 0xff00) << 8) | - ((n & 0xff0000UL) >> 8) | - ((n & 0xff000000UL) >> 24); -} - -#define ntohl htonl +EXP_FUNC int STDCALL ax_open(const char *pathname, int flags); #ifdef CONFIG_PLATFORM_LINUX void exit_now(const char *format, ...) __attribute((noreturn)); diff --git a/ssl/tls1.h b/ssl/tls1.h index e0a008c1b..624fe9dfd 100644 --- a/ssl/tls1.h +++ b/ssl/tls1.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2014, Cameron Rich + * Copyright (c) 2007-2016, Cameron Rich * * All rights reserved. * @@ -43,6 +43,7 @@ extern "C" { #include "version.h" #include "config.h" #include "os_int.h" +#include "os_port.h" #include "crypto.h" #include "crypto_misc.h"