mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-07 16:23:38 +03:00
removed some mallocs
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@123 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
parent
3515da26fb
commit
15651d6de5
20
ssl/rsa.c
20
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user