Now include os_port.h in tls1.h, but removed ax_malloc and friends
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@255 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
parent
ef28667444
commit
35a9bec2fd
5 changed files with 10 additions and 84 deletions
|
|
@ -104,7 +104,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))
|
||||
|
|
@ -124,7 +124,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
|
||||
}
|
||||
|
||||
|
|
@ -168,7 +168,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];
|
||||
|
|
@ -187,10 +187,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--)
|
||||
|
|
|
|||
|
|
@ -834,7 +834,7 @@ static int init_read_post_data(char *buf, char *data,
|
|||
{
|
||||
/* Allocate buffer for the POST data that will be used by proccgi
|
||||
to send POST data to the CGI script */
|
||||
cn->post_data = (char *)ax_calloc(1, (cn->content_length + 1));
|
||||
cn->post_data = (char *)calloc(1, (cn->content_length + 1));
|
||||
}
|
||||
|
||||
cn->post_state = 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Cameron Rich
|
||||
* Copyright (c) 2007-2016, Cameron Rich
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
|
|
@ -90,69 +90,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\"";
|
||||
|
||||
/*
|
||||
* Some functions that call display some error trace and then call abort().
|
||||
* This just makes life much easier on embedded systems, since we're
|
||||
* suffering major trauma...
|
||||
*/
|
||||
EXP_FUNC void * STDCALL ax_malloc(size_t s)
|
||||
{
|
||||
void *x;
|
||||
|
||||
if ((x = malloc(s)) == NULL)
|
||||
exit_now(out_of_mem_str);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s)
|
||||
{
|
||||
void *x;
|
||||
|
||||
if ((x = realloc(y, s)) == NULL)
|
||||
exit_now(out_of_mem_str);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s)
|
||||
{
|
||||
void *x;
|
||||
|
||||
if ((x = calloc(n, s)) == NULL)
|
||||
exit_now(out_of_mem_str);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags)
|
||||
{
|
||||
int x;
|
||||
|
||||
if ((x = open(pathname, flags)) < 0)
|
||||
exit_now(file_open_str, pathname);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a call which will deliberately exit an application, but will
|
||||
* display some information before dying.
|
||||
*/
|
||||
void exit_now(const char *format, ...)
|
||||
{
|
||||
va_list argp;
|
||||
|
||||
va_start(argp, format);
|
||||
vfprintf(stderr, format, argp);
|
||||
va_end(argp);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007-2015, Cameron Rich
|
||||
* Copyright (c) 2007-2016, Cameron Rich
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
|
|
@ -150,15 +150,6 @@ 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_malloc(A)
|
||||
#ifndef realloc
|
||||
#define realloc(A,B) ax_realloc(A,B)
|
||||
#endif
|
||||
#define calloc(A,B) ax_calloc(A,B)
|
||||
|
||||
EXP_FUNC void * STDCALL ax_malloc(size_t s);
|
||||
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s);
|
||||
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s);
|
||||
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags);
|
||||
|
||||
#ifdef CONFIG_PLATFORM_LINUX
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue