Commit fc8517bf authored by Sabrina Dubroca's avatar Sabrina Dubroca Committed by Herbert Xu

crypto: aesni - add wrapper for generic gcm(aes)

When I added generic-gcm-aes I didn't add a wrapper like the one
provided for rfc4106(gcm(aes)). We need to add a cryptd wrapper to fall
back on in case the FPU is not available, otherwise we might corrupt the
FPU state.

Fixes: cce2ea8d ("crypto: aesni - add generic gcm(aes)")
Cc: <stable@vger.kernel.org>
Reported-by: default avatarIlya Lesokhin <ilyal@mellanox.com>
Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Reviewed-by: default avatarStefano Brivio <sbrivio@redhat.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 106840c4
...@@ -690,7 +690,7 @@ static int common_rfc4106_set_key(struct crypto_aead *aead, const u8 *key, ...@@ -690,7 +690,7 @@ static int common_rfc4106_set_key(struct crypto_aead *aead, const u8 *key,
rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len); rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len);
} }
static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key, static int gcmaes_wrapper_set_key(struct crypto_aead *parent, const u8 *key,
unsigned int key_len) unsigned int key_len)
{ {
struct cryptd_aead **ctx = crypto_aead_ctx(parent); struct cryptd_aead **ctx = crypto_aead_ctx(parent);
...@@ -716,7 +716,7 @@ static int common_rfc4106_set_authsize(struct crypto_aead *aead, ...@@ -716,7 +716,7 @@ static int common_rfc4106_set_authsize(struct crypto_aead *aead,
/* This is the Integrity Check Value (aka the authentication tag length and can /* This is the Integrity Check Value (aka the authentication tag length and can
* be 8, 12 or 16 bytes long. */ * be 8, 12 or 16 bytes long. */
static int rfc4106_set_authsize(struct crypto_aead *parent, static int gcmaes_wrapper_set_authsize(struct crypto_aead *parent,
unsigned int authsize) unsigned int authsize)
{ {
struct cryptd_aead **ctx = crypto_aead_ctx(parent); struct cryptd_aead **ctx = crypto_aead_ctx(parent);
...@@ -929,7 +929,7 @@ static int helper_rfc4106_decrypt(struct aead_request *req) ...@@ -929,7 +929,7 @@ static int helper_rfc4106_decrypt(struct aead_request *req)
aes_ctx); aes_ctx);
} }
static int rfc4106_encrypt(struct aead_request *req) static int gcmaes_wrapper_encrypt(struct aead_request *req)
{ {
struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct crypto_aead *tfm = crypto_aead_reqtfm(req);
struct cryptd_aead **ctx = crypto_aead_ctx(tfm); struct cryptd_aead **ctx = crypto_aead_ctx(tfm);
...@@ -945,7 +945,7 @@ static int rfc4106_encrypt(struct aead_request *req) ...@@ -945,7 +945,7 @@ static int rfc4106_encrypt(struct aead_request *req)
return crypto_aead_encrypt(req); return crypto_aead_encrypt(req);
} }
static int rfc4106_decrypt(struct aead_request *req) static int gcmaes_wrapper_decrypt(struct aead_request *req)
{ {
struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct crypto_aead *tfm = crypto_aead_reqtfm(req);
struct cryptd_aead **ctx = crypto_aead_ctx(tfm); struct cryptd_aead **ctx = crypto_aead_ctx(tfm);
...@@ -1128,6 +1128,30 @@ static int generic_gcmaes_decrypt(struct aead_request *req) ...@@ -1128,6 +1128,30 @@ static int generic_gcmaes_decrypt(struct aead_request *req)
aes_ctx); aes_ctx);
} }
static int generic_gcmaes_init(struct crypto_aead *aead)
{
struct cryptd_aead *cryptd_tfm;
struct cryptd_aead **ctx = crypto_aead_ctx(aead);
cryptd_tfm = cryptd_alloc_aead("__driver-generic-gcm-aes-aesni",
CRYPTO_ALG_INTERNAL,
CRYPTO_ALG_INTERNAL);
if (IS_ERR(cryptd_tfm))
return PTR_ERR(cryptd_tfm);
*ctx = cryptd_tfm;
crypto_aead_set_reqsize(aead, crypto_aead_reqsize(&cryptd_tfm->base));
return 0;
}
static void generic_gcmaes_exit(struct crypto_aead *aead)
{
struct cryptd_aead **ctx = crypto_aead_ctx(aead);
cryptd_free_aead(*ctx);
}
static struct aead_alg aesni_aead_algs[] = { { static struct aead_alg aesni_aead_algs[] = { {
.setkey = common_rfc4106_set_key, .setkey = common_rfc4106_set_key,
.setauthsize = common_rfc4106_set_authsize, .setauthsize = common_rfc4106_set_authsize,
...@@ -1147,10 +1171,10 @@ static struct aead_alg aesni_aead_algs[] = { { ...@@ -1147,10 +1171,10 @@ static struct aead_alg aesni_aead_algs[] = { {
}, { }, {
.init = rfc4106_init, .init = rfc4106_init,
.exit = rfc4106_exit, .exit = rfc4106_exit,
.setkey = rfc4106_set_key, .setkey = gcmaes_wrapper_set_key,
.setauthsize = rfc4106_set_authsize, .setauthsize = gcmaes_wrapper_set_authsize,
.encrypt = rfc4106_encrypt, .encrypt = gcmaes_wrapper_encrypt,
.decrypt = rfc4106_decrypt, .decrypt = gcmaes_wrapper_decrypt,
.ivsize = GCM_RFC4106_IV_SIZE, .ivsize = GCM_RFC4106_IV_SIZE,
.maxauthsize = 16, .maxauthsize = 16,
.base = { .base = {
...@@ -1169,14 +1193,32 @@ static struct aead_alg aesni_aead_algs[] = { { ...@@ -1169,14 +1193,32 @@ static struct aead_alg aesni_aead_algs[] = { {
.decrypt = generic_gcmaes_decrypt, .decrypt = generic_gcmaes_decrypt,
.ivsize = GCM_AES_IV_SIZE, .ivsize = GCM_AES_IV_SIZE,
.maxauthsize = 16, .maxauthsize = 16,
.base = {
.cra_name = "__generic-gcm-aes-aesni",
.cra_driver_name = "__driver-generic-gcm-aes-aesni",
.cra_priority = 0,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = 1,
.cra_ctxsize = sizeof(struct generic_gcmaes_ctx),
.cra_alignmask = AESNI_ALIGN - 1,
.cra_module = THIS_MODULE,
},
}, {
.init = generic_gcmaes_init,
.exit = generic_gcmaes_exit,
.setkey = gcmaes_wrapper_set_key,
.setauthsize = gcmaes_wrapper_set_authsize,
.encrypt = gcmaes_wrapper_encrypt,
.decrypt = gcmaes_wrapper_decrypt,
.ivsize = GCM_AES_IV_SIZE,
.maxauthsize = 16,
.base = { .base = {
.cra_name = "gcm(aes)", .cra_name = "gcm(aes)",
.cra_driver_name = "generic-gcm-aesni", .cra_driver_name = "generic-gcm-aesni",
.cra_priority = 400, .cra_priority = 400,
.cra_flags = CRYPTO_ALG_ASYNC, .cra_flags = CRYPTO_ALG_ASYNC,
.cra_blocksize = 1, .cra_blocksize = 1,
.cra_ctxsize = sizeof(struct generic_gcmaes_ctx), .cra_ctxsize = sizeof(struct cryptd_aead *),
.cra_alignmask = AESNI_ALIGN - 1,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
}, },
} }; } };
......
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