crypto: caam - check authsize
authorIuliana Prodan <iuliana.prodan@nxp.com>
Wed, 31 Jul 2019 13:08:06 +0000 (16:08 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 9 Aug 2019 05:11:46 +0000 (15:11 +1000)
Check authsize to solve the extra tests that expect -EINVAL to be
returned when the authentication tag size is not valid.

Validated authsize for GCM, RFC4106 and RFC4543.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geanta <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/caamalg_qi.c
drivers/crypto/caam/caamalg_qi2.c

index ce50ae1dc82545d5248e8dda55ccf8a10f733cc0..591906988a229aede21524deeb8dd43562e85872 100644 (file)
@@ -376,6 +376,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead)
 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
+       int err;
+
+       err = crypto_gcm_check_authsize(authsize);
+       if (err)
+               return err;
 
        ctx->authsize = authsize;
        gcm_set_sh_desc(authenc);
@@ -439,6 +444,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
                               unsigned int authsize)
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
+       int err;
+
+       err = crypto_rfc4106_check_authsize(authsize);
+       if (err)
+               return err;
 
        ctx->authsize = authsize;
        rfc4106_set_sh_desc(authenc);
@@ -503,6 +513,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
 
+       if (authsize != 16)
+               return -EINVAL;
+
        ctx->authsize = authsize;
        rfc4543_set_sh_desc(authenc);
 
index b8854f268e5a24264489c90bb8a5ffc8ee49e3a4..6c69f54d1f79f56925f77b969c134e17966d3fc2 100644 (file)
@@ -371,6 +371,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead)
 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
+       int err;
+
+       err = crypto_gcm_check_authsize(authsize);
+       if (err)
+               return err;
 
        ctx->authsize = authsize;
        gcm_set_sh_desc(authenc);
@@ -472,6 +477,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
                               unsigned int authsize)
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
+       int err;
+
+       err = crypto_rfc4106_check_authsize(authsize);
+       if (err)
+               return err;
 
        ctx->authsize = authsize;
        rfc4106_set_sh_desc(authenc);
@@ -578,6 +588,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
 
+       if (authsize != 16)
+               return -EINVAL;
+
        ctx->authsize = authsize;
        rfc4543_set_sh_desc(authenc);
 
index 337150bdf3d1a8b36c522d8387db482396aa6946..141d6231e4b9aed21f847bbf3058bf9fb9ae8af7 100644 (file)
@@ -720,6 +720,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead)
 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
+       int err;
+
+       err = crypto_gcm_check_authsize(authsize);
+       if (err)
+               return err;
 
        ctx->authsize = authsize;
        gcm_set_sh_desc(authenc);
@@ -812,6 +817,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
                               unsigned int authsize)
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
+       int err;
+
+       err = crypto_rfc4106_check_authsize(authsize);
+       if (err)
+               return err;
 
        ctx->authsize = authsize;
        rfc4106_set_sh_desc(authenc);
@@ -911,6 +921,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
 {
        struct caam_ctx *ctx = crypto_aead_ctx(authenc);
 
+       if (authsize != 16)
+               return -EINVAL;
+
        ctx->authsize = authsize;
        rfc4543_set_sh_desc(authenc);