From 15651d6de5ded84c4936bb8261a7c173f89b4bab Mon Sep 17 00:00:00 2001 From: cameronrich Date: Mon, 10 Sep 2007 21:48:04 +0000 Subject: [PATCH] removed some mallocs git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@123 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- ssl/rsa.c | 20 +++++++++++++++----- ssl/tls1.c | 7 ++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ssl/rsa.c b/ssl/rsa.c index 97c5e6700..bcfc31016 100644 --- a/ssl/rsa.c +++ b/ssl/rsa.c @@ -125,10 +125,14 @@ void RSA_free(RSA_CTX *rsa_ctx) int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, uint8_t *out_data, int is_decryption) { - int byte_size = ctx->num_octets; - uint8_t *block; + const int byte_size = ctx->num_octets; int i, size; bigint *decrypted_bi, *dat_bi; +#ifndef WIN32 + uint8_t block[byte_size]; +#else + uint8_t *block = (uint8_t *)malloc(byte_size); +#endif memset(out_data, 0, byte_size); /* initialise */ @@ -142,7 +146,6 @@ int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, #endif /* convert to a normal block */ - block = (uint8_t *)malloc(byte_size); bi_export(ctx->bi_ctx, decrypted_bi, block, byte_size); i = 10; /* start at the first possible non-padded byte */ @@ -166,7 +169,9 @@ int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, if (size > 0) memcpy(out_data, &block[i], size); +#ifdef WIN32 free(block); +#endif return size ? size : -1; } @@ -253,11 +258,14 @@ int RSA_encrypt(const RSA_CTX *ctx, const uint8_t *in_data, uint16_t in_len, bigint *RSA_sign_verify(BI_CTX *ctx, const uint8_t *sig, int sig_len, bigint *modulus, bigint *pub_exp) { - uint8_t *block; int i, size; bigint *decrypted_bi, *dat_bi; bigint *bir = NULL; - block = (uint8_t *)malloc(sig_len); +#ifndef WIN32 + uint8_t block[sig_len]; +#else + uint8_t *block = (uint8_t *)malloc(sig_len); +#endif /* decrypt */ dat_bi = bi_import(ctx, sig, sig_len); @@ -285,7 +293,9 @@ bigint *RSA_sign_verify(BI_CTX *ctx, const uint8_t *sig, int sig_len, } } +#ifdef WIN32 free(block); +#endif return bir; } diff --git a/ssl/tls1.c b/ssl/tls1.c index de5597fbd..0e2ced092 100755 --- a/ssl/tls1.c +++ b/ssl/tls1.c @@ -623,7 +623,11 @@ static void add_hmac_digest(SSL *ssl, int mode, uint8_t *hmac_header, const uint8_t *buf, int buf_len, uint8_t *hmac_buf) { int hmac_len = buf_len + 8 + SSL_RECORD_SIZE; +#ifndef WIN32 + uint8_t t_buf[hmac_len+10]; +#else uint8_t *t_buf = (uint8_t *)malloc(hmac_len+10); +#endif memcpy(t_buf, (mode == SSL_SERVER_WRITE || mode == SSL_CLIENT_WRITE) ? ssl->write_sequence : ssl->read_sequence, 8); @@ -659,8 +663,9 @@ static void add_hmac_digest(SSL *ssl, int mode, uint8_t *hmac_header, } print_blob("hmac", hmac_buf, SHA1_SIZE); #endif - +#ifdef WIN32 free(t_buf); +#endif } /**