crypto/openssl: fix usage of non constant time memcmp for mac and signature

Message ID 20190531065928.3420-2-arkadiuszx.kusztal@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series crypto/openssl: fix usage of non constant time memcmp for mac and signature |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation fail Compilation issues

Commit Message

Arkadiusz Kusztal May 31, 2019, 6:59 a.m. UTC
  ANSI C memcmp is not constant time function per spec so it should
be avoided in cryptography usage.

Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library")

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/crypto/openssl/rte_openssl_pmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Fiona Trahe May 31, 2019, 2:53 p.m. UTC | #1
> -----Original Message-----
> From: Kusztal, ArkadiuszX
> Sent: Friday, May 31, 2019 7:59 AM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Trahe, Fiona <fiona.trahe@intel.com>; Doherty, Declan
> <declan.doherty@intel.com>; Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>
> Subject: [PATCH] crypto/openssl: fix usage of non constant time memcmp for mac and signature
> 
> ANSI C memcmp is not constant time function per spec so it should
> be avoided in cryptography usage.
> 
> Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library")
> 
> Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> ---
>  drivers/crypto/openssl/rte_openssl_pmd.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
> index 6504959..73ce383 100644
> --- a/drivers/crypto/openssl/rte_openssl_pmd.c
> +++ b/drivers/crypto/openssl/rte_openssl_pmd.c
> @@ -1529,7 +1529,7 @@ process_openssl_auth_op(struct openssl_qp *qp, struct rte_crypto_op *op,
>  	}
> 
>  	if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
> -		if (memcmp(dst, op->sym->auth.digest.data,
> +		if (CRYPTO_memcmp(dst, op->sym->auth.digest.data,
>  				sess->auth.digest_length) != 0) {
>  			op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
>  		}
> @@ -1914,7 +1914,7 @@ process_openssl_rsa_op(struct rte_crypto_op *cop,
>  				"Length of public_decrypt %d "
>  				"length of message %zd\n",
>  				ret, op->rsa.message.length);
> -		if ((ret <= 0) || (memcmp(tmp, op->rsa.message.data,
> +		if ((ret <= 0) || (CRYPTO_memcmp(tmp, op->rsa.message.data,
>  				op->rsa.message.length))) {
>  			OPENSSL_LOG(ERR, "RSA sign Verification failed");
>  			cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
> --
> 2.1.0
Hadn't heard of that time const fn before so just read up on it - interesting.
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
  
Akhil Goyal June 19, 2019, 2:48 p.m. UTC | #2
> 
> 
> > -----Original Message-----
> > From: Kusztal, ArkadiuszX
> > Sent: Friday, May 31, 2019 7:59 AM
> > To: dev@dpdk.org
> > Cc: akhil.goyal@nxp.com; Trahe, Fiona <fiona.trahe@intel.com>; Doherty,
> Declan
> > <declan.doherty@intel.com>; Kusztal, ArkadiuszX
> <arkadiuszx.kusztal@intel.com>
> > Subject: [PATCH] crypto/openssl: fix usage of non constant time memcmp for
> mac and signature
> >
> > ANSI C memcmp is not constant time function per spec so it should
> > be avoided in cryptography usage.
> >
> > Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library")
> >
> > Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> > ---
> >  drivers/crypto/openssl/rte_openssl_pmd.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c
> b/drivers/crypto/openssl/rte_openssl_pmd.c
> > index 6504959..73ce383 100644
> > --- a/drivers/crypto/openssl/rte_openssl_pmd.c
> > +++ b/drivers/crypto/openssl/rte_openssl_pmd.c
> > @@ -1529,7 +1529,7 @@ process_openssl_auth_op(struct openssl_qp *qp,
> struct rte_crypto_op *op,
> >  	}
> >
> >  	if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
> > -		if (memcmp(dst, op->sym->auth.digest.data,
> > +		if (CRYPTO_memcmp(dst, op->sym->auth.digest.data,
> >  				sess->auth.digest_length) != 0) {
> >  			op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
> >  		}
> > @@ -1914,7 +1914,7 @@ process_openssl_rsa_op(struct rte_crypto_op *cop,
> >  				"Length of public_decrypt %d "
> >  				"length of message %zd\n",
> >  				ret, op->rsa.message.length);
> > -		if ((ret <= 0) || (memcmp(tmp, op->rsa.message.data,
> > +		if ((ret <= 0) || (CRYPTO_memcmp(tmp, op->rsa.message.data,
> >  				op->rsa.message.length))) {
> >  			OPENSSL_LOG(ERR, "RSA sign Verification failed");
> >  			cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
> > --
> > 2.1.0
> Hadn't heard of that time const fn before so just read up on it - interesting.
> Acked-by: Fiona Trahe <fiona.trahe@intel.com>
> 
Modified the subject a bit.
Applied to dpdk-next-crypto

Thanks
  

Patch

diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 6504959..73ce383 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -1529,7 +1529,7 @@  process_openssl_auth_op(struct openssl_qp *qp, struct rte_crypto_op *op,
 	}
 
 	if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
-		if (memcmp(dst, op->sym->auth.digest.data,
+		if (CRYPTO_memcmp(dst, op->sym->auth.digest.data,
 				sess->auth.digest_length) != 0) {
 			op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
 		}
@@ -1914,7 +1914,7 @@  process_openssl_rsa_op(struct rte_crypto_op *cop,
 				"Length of public_decrypt %d "
 				"length of message %zd\n",
 				ret, op->rsa.message.length);
-		if ((ret <= 0) || (memcmp(tmp, op->rsa.message.data,
+		if ((ret <= 0) || (CRYPTO_memcmp(tmp, op->rsa.message.data,
 				op->rsa.message.length))) {
 			OPENSSL_LOG(ERR, "RSA sign Verification failed");
 			cop->status = RTE_CRYPTO_OP_STATUS_ERROR;