X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fopenssl%2Fcipher.c;h=5d9bebcdb68e9b4f8d1cbfac05c4c1768fa31655;hb=c7752ca73e582d63412e7f40984cff2fca02c22f;hp=32cb5ce2d138a491f0dfeae8fadfe4571da09ff8;hpb=9b9230a0a79c670b86f54fadd2807b864ff9d91f;p=tinc diff --git a/src/openssl/cipher.c b/src/openssl/cipher.c index 32cb5ce2..5d9bebcd 100644 --- a/src/openssl/cipher.c +++ b/src/openssl/cipher.c @@ -40,7 +40,7 @@ typedef struct cipher_counter { } cipher_counter_t; static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) { - cipher_t *cipher = xmalloc_and_zero(sizeof *cipher); + cipher_t *cipher = xzalloc(sizeof *cipher); cipher->cipher = evp_cipher; EVP_CIPHER_CTX_init(&cipher->ctx); @@ -81,6 +81,9 @@ void cipher_close(cipher_t *cipher) { } size_t cipher_keylength(const cipher_t *cipher) { + if(!cipher || !cipher->cipher) + return 0; + return cipher->cipher->key_len + cipher->cipher->block_size; } @@ -135,7 +138,7 @@ bool cipher_set_counter_key(cipher_t *cipher, void *key) { } if(!cipher->counter) - cipher->counter = xmalloc_and_zero(sizeof *cipher->counter); + cipher->counter = xzalloc(sizeof *cipher->counter); else cipher->counter->n = 0; @@ -168,7 +171,7 @@ bool cipher_counter_xor(cipher_t *cipher, const void *indata, size_t inlen, void break; } - *out++ = *in++ ^ cipher->counter->counter[cipher->counter->n++]; + *out++ = *in++ ^ cipher->counter->block[cipher->counter->n++]; if(cipher->counter->n >= cipher->cipher->block_size) cipher->counter->n = 0; @@ -221,7 +224,10 @@ bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou } int cipher_get_nid(const cipher_t *cipher) { - return cipher->cipher ? cipher->cipher->nid : 0; + if(!cipher || !cipher->cipher) + return 0; + + return cipher->cipher->nid; } bool cipher_active(const cipher_t *cipher) {