summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-03-01 14:46:04 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-03-01 14:46:04 +0800
commit0147fa3408e07926165142b1c479dbe3b11efccf (patch)
tree5a49baae4c618119ec60b3bfd0ebd2a3132c109a
parente65c9c75dc0efb9bbf8f7e292e4ba5532e31ae81 (diff)
downloaddropbear-0147fa3408e07926165142b1c479dbe3b11efccf.tar.gz
Avoid malloc in hmac
-rw-r--r--libtomcrypt/src/mac/hmac/hmac_done.c18
-rw-r--r--libtomcrypt/src/mac/hmac/hmac_init.c10
2 files changed, 2 insertions, 26 deletions
diff --git a/libtomcrypt/src/mac/hmac/hmac_done.c b/libtomcrypt/src/mac/hmac/hmac_done.c
index 5ba541a..f48d672 100644
--- a/libtomcrypt/src/mac/hmac/hmac_done.c
+++ b/libtomcrypt/src/mac/hmac/hmac_done.c
@@ -28,7 +28,7 @@
*/
int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
{
- unsigned char *buf, *isha;
+ unsigned char buf[MAXBLOCKSIZE], isha[MAXBLOCKSIZE];
unsigned long hashsize, i;
int hash, err;
@@ -44,19 +44,6 @@ int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
/* get the hash message digest size */
hashsize = hash_descriptor[hash].hashsize;
- /* allocate buffers */
- buf = XMALLOC(HMAC_BLOCKSIZE);
- isha = XMALLOC(hashsize);
- if (buf == NULL || isha == NULL) {
- if (buf != NULL) {
- XFREE(buf);
- }
- if (isha != NULL) {
- XFREE(isha);
- }
- return CRYPT_MEM;
- }
-
/* Get the hash of the first HMAC vector plus the data */
if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
goto LBL_ERR;
@@ -96,9 +83,6 @@ LBL_ERR:
zeromem(hmac, sizeof(*hmac));
#endif
- XFREE(isha);
- XFREE(buf);
-
return err;
}
diff --git a/libtomcrypt/src/mac/hmac/hmac_init.c b/libtomcrypt/src/mac/hmac/hmac_init.c
index 2d61a9a..a4a4377 100644
--- a/libtomcrypt/src/mac/hmac/hmac_init.c
+++ b/libtomcrypt/src/mac/hmac/hmac_init.c
@@ -29,7 +29,7 @@
*/
int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen)
{
- unsigned char *buf;
+ unsigned char buf[MAXBLOCKSIZE];
unsigned long hashsize;
unsigned long i, z;
int err;
@@ -49,16 +49,9 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
return CRYPT_INVALID_KEYSIZE;
}
- /* allocate ram for buf */
- buf = XMALLOC(HMAC_BLOCKSIZE);
- if (buf == NULL) {
- return CRYPT_MEM;
- }
-
/* allocate memory for key */
hmac->key = XMALLOC(HMAC_BLOCKSIZE);
if (hmac->key == NULL) {
- XFREE(buf);
return CRYPT_MEM;
}
@@ -101,7 +94,6 @@ done:
zeromem(buf, HMAC_BLOCKSIZE);
#endif
- XFREE(buf);
return err;
}