From 546ac7936340312cf272969ff83317ae4d50d2b4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Aug 2014 00:53:47 +0200 Subject: Introduce and use alloc helpers These new helpers will terminate fastd on allocation failures and add some additional convenience (allow strdup with NULL; typesafe new(type) macros). --- src/crypto/cipher/salsa20/nacl/salsa20_nacl.c | 3 ++- src/crypto/cipher/salsa20/xmm/salsa20_xmm.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/crypto/cipher/salsa20') diff --git a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c index 6179bc2..b9c2175 100644 --- a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c +++ b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c @@ -30,6 +30,7 @@ */ +#include "../../../../alloc.h" #include "../../../../crypto.h" #include @@ -43,7 +44,7 @@ struct fastd_cipher_state { /** Initializes the cipher state */ static fastd_cipher_state_t* salsa20_init(const uint8_t *key) { - fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t)); + fastd_cipher_state_t *state = fastd_new(fastd_cipher_state_t); memcpy(state->key, key, crypto_stream_salsa20_KEYBYTES); return state; diff --git a/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c b/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c index a85ed72..abf717f 100644 --- a/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c +++ b/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c @@ -33,6 +33,7 @@ */ +#include "../../../../alloc.h" #include "../../../../crypto.h" #include "../../../../cpuid.h" @@ -67,7 +68,7 @@ static bool salsa20_available(void) { /** Initializes the cipher state */ static fastd_cipher_state_t* salsa20_init(const uint8_t *key) { - fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t)); + fastd_cipher_state_t *state = fastd_new(fastd_cipher_state_t); memcpy(state->key, key, KEYBYTES); return state; -- cgit v1.2.3