Skip to content

Commit 35a9bec

Browse files
author
cameronrich
committed
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
1 parent ef28667 commit 35a9bec

File tree

5 files changed

+10
-84
lines changed

5 files changed

+10
-84
lines changed

crypto/crypto_misc.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int get_file(const char *filename, uint8_t **buf)
104104
EXP_FUNC void STDCALL RNG_initialize()
105105
{
106106
#if !defined(WIN32) && defined(CONFIG_USE_DEV_URANDOM)
107-
rng_fd = ax_open("/dev/urandom", O_RDONLY);
107+
rng_fd = open("/dev/urandom", O_RDONLY);
108108
#elif defined(WIN32) && defined(CONFIG_WIN32_USE_CRYPTO_LIB)
109109
if (!CryptAcquireContext(&gCryptProv,
110110
NULL, NULL, PROV_RSA_FULL, 0))
@@ -124,7 +124,7 @@ EXP_FUNC void STDCALL RNG_initialize()
124124
/* start of with a stack to copy across */
125125
int i;
126126
memcpy(entropy_pool, &i, ENTROPY_POOL_SIZE);
127-
srand((unsigned int)&i);
127+
rand_r((unsigned int *)entropy_pool);
128128
#endif
129129
}
130130

@@ -168,7 +168,7 @@ EXP_FUNC int STDCALL get_random(int num_rand_bytes, uint8_t *rand_data)
168168
#else /* nothing else to use, so use a custom RNG */
169169
/* The method we use when we've got nothing better. Use RC4, time
170170
and a couple of random seeds to generate a random sequence */
171-
RC4_CTX rng_ctx;
171+
AES_CTX rng_ctx;
172172
struct timeval tv;
173173
MD5_CTX rng_digest_ctx;
174174
uint8_t digest[MD5_SIZE];
@@ -187,10 +187,10 @@ EXP_FUNC int STDCALL get_random(int num_rand_bytes, uint8_t *rand_data)
187187
MD5_Final(digest, &rng_digest_ctx);
188188

189189
/* come up with the random sequence */
190-
RC4_setup(&rng_ctx, digest, MD5_SIZE); /* use as a key */
190+
AES_set_key(&rng_ctx, digest, (const uint8_t *)ep, AES_MODE_128); /* use as a key */
191191
memcpy(rand_data, entropy_pool, num_rand_bytes < ENTROPY_POOL_SIZE ?
192192
num_rand_bytes : ENTROPY_POOL_SIZE);
193-
RC4_crypt(&rng_ctx, rand_data, rand_data, num_rand_bytes);
193+
AES_cbc_encrypt(&rng_ctx, rand_data, rand_data, num_rand_bytes);
194194

195195
/* move things along */
196196
for (i = ENTROPY_POOL_SIZE-1; i >= MD5_SIZE ; i--)

httpd/proc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ static int init_read_post_data(char *buf, char *data,
834834
{
835835
/* Allocate buffer for the POST data that will be used by proccgi
836836
to send POST data to the CGI script */
837-
cn->post_data = (char *)ax_calloc(1, (cn->content_length + 1));
837+
cn->post_data = (char *)calloc(1, (cn->content_length + 1));
838838
}
839839

840840
cn->post_state = 0;

ssl/os_port.c

+1-67
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Cameron Rich
2+
* Copyright (c) 2007-2016, Cameron Rich
33
*
44
* All rights reserved.
55
*
@@ -90,69 +90,3 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size)
9090
}
9191
#endif
9292

93-
#undef malloc
94-
#undef realloc
95-
#undef calloc
96-
97-
static const char * out_of_mem_str = "out of memory";
98-
static const char * file_open_str = "Could not open file \"%s\"";
99-
100-
/*
101-
* Some functions that call display some error trace and then call abort().
102-
* This just makes life much easier on embedded systems, since we're
103-
* suffering major trauma...
104-
*/
105-
EXP_FUNC void * STDCALL ax_malloc(size_t s)
106-
{
107-
void *x;
108-
109-
if ((x = malloc(s)) == NULL)
110-
exit_now(out_of_mem_str);
111-
112-
return x;
113-
}
114-
115-
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s)
116-
{
117-
void *x;
118-
119-
if ((x = realloc(y, s)) == NULL)
120-
exit_now(out_of_mem_str);
121-
122-
return x;
123-
}
124-
125-
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s)
126-
{
127-
void *x;
128-
129-
if ((x = calloc(n, s)) == NULL)
130-
exit_now(out_of_mem_str);
131-
132-
return x;
133-
}
134-
135-
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags)
136-
{
137-
int x;
138-
139-
if ((x = open(pathname, flags)) < 0)
140-
exit_now(file_open_str, pathname);
141-
142-
return x;
143-
}
144-
145-
/**
146-
* This is a call which will deliberately exit an application, but will
147-
* display some information before dying.
148-
*/
149-
void exit_now(const char *format, ...)
150-
{
151-
va_list argp;
152-
153-
va_start(argp, format);
154-
vfprintf(stderr, format, argp);
155-
va_end(argp);
156-
abort();
157-
}
158-

ssl/os_port.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007-2015, Cameron Rich
2+
* Copyright (c) 2007-2016, Cameron Rich
33
*
44
* All rights reserved.
55
*
@@ -150,15 +150,6 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size);
150150
#endif /* Not Win32 */
151151

152152
/* some functions to mutate the way these work */
153-
#define malloc(A) ax_malloc(A)
154-
#ifndef realloc
155-
#define realloc(A,B) ax_realloc(A,B)
156-
#endif
157-
#define calloc(A,B) ax_calloc(A,B)
158-
159-
EXP_FUNC void * STDCALL ax_malloc(size_t s);
160-
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s);
161-
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s);
162153
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags);
163154

164155
#ifdef CONFIG_PLATFORM_LINUX

ssl/tls1.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007-2014, Cameron Rich
2+
* Copyright (c) 2007-2016, Cameron Rich
33
*
44
* All rights reserved.
55
*
@@ -43,6 +43,7 @@ extern "C" {
4343
#include "version.h"
4444
#include "config.h"
4545
#include "os_int.h"
46+
#include "os_port.h"
4647
#include "crypto.h"
4748
#include "crypto_misc.h"
4849

0 commit comments

Comments
 (0)