From 3b4d39ea45ed780f4504af2ccfce43efabc3b854 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 3 Aug 2017 13:40:26 +0200 Subject: [PATCH] OCBv3: improve a bit when ARGCHK'ing pointers * it didn't really make sense to check that the _in_ pointer is NULL * instead we should check that _in_ and _out_ are not NULL when there's something to process --- src/encauth/ocb3/ocb3_decrypt.c | 6 ++++-- src/encauth/ocb3/ocb3_decrypt_last.c | 6 ++++-- src/encauth/ocb3/ocb3_encrypt.c | 6 ++++-- src/encauth/ocb3/ocb3_encrypt_last.c | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/encauth/ocb3/ocb3_decrypt.c b/src/encauth/ocb3/ocb3_decrypt.c index da1a70d..1824bc3 100644 --- a/src/encauth/ocb3/ocb3_decrypt.c +++ b/src/encauth/ocb3/ocb3_decrypt.c @@ -31,8 +31,10 @@ int ocb3_decrypt(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen, LTC_ARGCHK(ocb != NULL); if (ct == NULL) LTC_ARGCHK(ctlen == 0); - if (ctlen == 0) LTC_ARGCHK(ct == NULL); - else LTC_ARGCHK(pt != NULL); + if (ctlen != 0) { + LTC_ARGCHK(ct != NULL); + LTC_ARGCHK(pt != NULL); + } if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { return err; diff --git a/src/encauth/ocb3/ocb3_decrypt_last.c b/src/encauth/ocb3/ocb3_decrypt_last.c index d92d0ed..70608dc 100644 --- a/src/encauth/ocb3/ocb3_decrypt_last.c +++ b/src/encauth/ocb3/ocb3_decrypt_last.c @@ -31,8 +31,10 @@ int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ct LTC_ARGCHK(ocb != NULL); if (ct == NULL) LTC_ARGCHK(ctlen == 0); - if (ctlen == 0) LTC_ARGCHK(ct == NULL); - else LTC_ARGCHK(pt != NULL); + if (ctlen != 0) { + LTC_ARGCHK(ct != NULL); + LTC_ARGCHK(pt != NULL); + } if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { goto LBL_ERR; diff --git a/src/encauth/ocb3/ocb3_encrypt.c b/src/encauth/ocb3/ocb3_encrypt.c index be7438d..3349554 100644 --- a/src/encauth/ocb3/ocb3_encrypt.c +++ b/src/encauth/ocb3/ocb3_encrypt.c @@ -31,8 +31,10 @@ int ocb3_encrypt(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen, LTC_ARGCHK(ocb != NULL); if (pt == NULL) LTC_ARGCHK(ptlen == 0); - if (ptlen == 0) LTC_ARGCHK(pt == NULL); - else LTC_ARGCHK(ct != NULL); + if (ptlen != 0) { + LTC_ARGCHK(pt != NULL); + LTC_ARGCHK(ct != NULL); + } if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { return err; diff --git a/src/encauth/ocb3/ocb3_encrypt_last.c b/src/encauth/ocb3/ocb3_encrypt_last.c index fb5adb8..8110a3c 100644 --- a/src/encauth/ocb3/ocb3_encrypt_last.c +++ b/src/encauth/ocb3/ocb3_encrypt_last.c @@ -31,8 +31,10 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt LTC_ARGCHK(ocb != NULL); if (pt == NULL) LTC_ARGCHK(ptlen == 0); - if (ptlen == 0) LTC_ARGCHK(pt == NULL); - else LTC_ARGCHK(ct != NULL); + if (ptlen != 0) { + LTC_ARGCHK(pt != NULL); + LTC_ARGCHK(ct != NULL); + } if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { goto LBL_ERR;