Commit 68a51394 authored by Iuliana Prodan's avatar Iuliana Prodan Committed by Herbert Xu

crypto: caam - check authsize

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: default avatarIuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: default avatarHoria Geanta <horia.geanta@nxp.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 836d8f43
...@@ -376,6 +376,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) ...@@ -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) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
int err;
err = crypto_gcm_check_authsize(authsize);
if (err)
return err;
ctx->authsize = authsize; ctx->authsize = authsize;
gcm_set_sh_desc(authenc); gcm_set_sh_desc(authenc);
...@@ -439,6 +444,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, ...@@ -439,6 +444,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
unsigned int authsize) unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
int err;
err = crypto_rfc4106_check_authsize(authsize);
if (err)
return err;
ctx->authsize = authsize; ctx->authsize = authsize;
rfc4106_set_sh_desc(authenc); rfc4106_set_sh_desc(authenc);
...@@ -503,6 +513,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, ...@@ -503,6 +513,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
if (authsize != 16)
return -EINVAL;
ctx->authsize = authsize; ctx->authsize = authsize;
rfc4543_set_sh_desc(authenc); rfc4543_set_sh_desc(authenc);
......
...@@ -371,6 +371,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) ...@@ -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) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
int err;
err = crypto_gcm_check_authsize(authsize);
if (err)
return err;
ctx->authsize = authsize; ctx->authsize = authsize;
gcm_set_sh_desc(authenc); gcm_set_sh_desc(authenc);
...@@ -472,6 +477,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, ...@@ -472,6 +477,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
unsigned int authsize) unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
int err;
err = crypto_rfc4106_check_authsize(authsize);
if (err)
return err;
ctx->authsize = authsize; ctx->authsize = authsize;
rfc4106_set_sh_desc(authenc); rfc4106_set_sh_desc(authenc);
...@@ -578,6 +588,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, ...@@ -578,6 +588,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
if (authsize != 16)
return -EINVAL;
ctx->authsize = authsize; ctx->authsize = authsize;
rfc4543_set_sh_desc(authenc); rfc4543_set_sh_desc(authenc);
......
...@@ -720,6 +720,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) ...@@ -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) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
int err;
err = crypto_gcm_check_authsize(authsize);
if (err)
return err;
ctx->authsize = authsize; ctx->authsize = authsize;
gcm_set_sh_desc(authenc); gcm_set_sh_desc(authenc);
...@@ -812,6 +817,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, ...@@ -812,6 +817,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
unsigned int authsize) unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
int err;
err = crypto_rfc4106_check_authsize(authsize);
if (err)
return err;
ctx->authsize = authsize; ctx->authsize = authsize;
rfc4106_set_sh_desc(authenc); rfc4106_set_sh_desc(authenc);
...@@ -911,6 +921,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, ...@@ -911,6 +921,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx(authenc);
if (authsize != 16)
return -EINVAL;
ctx->authsize = authsize; ctx->authsize = authsize;
rfc4543_set_sh_desc(authenc); rfc4543_set_sh_desc(authenc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment