2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-08-30 07:36:14 +00:00
|
|
|
/*
|
|
|
|
* AEAD: Authenticated Encryption with Associated Data
|
2010-02-16 12:24:07 +00:00
|
|
|
*
|
2007-08-30 07:36:14 +00:00
|
|
|
* This file provides API support for AEAD algorithms.
|
|
|
|
*
|
2015-08-14 07:30:41 +00:00
|
|
|
* Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au>
|
2007-08-30 07:36:14 +00:00
|
|
|
*/
|
|
|
|
|
2019-11-08 10:41:58 +00:00
|
|
|
#include <crypto/internal/aead.h>
|
2023-02-16 10:35:11 +00:00
|
|
|
#include <linux/cryptouser.h>
|
2019-11-08 10:41:58 +00:00
|
|
|
#include <linux/errno.h>
|
2007-08-30 07:36:14 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/seq_file.h>
|
2023-02-16 10:35:11 +00:00
|
|
|
#include <linux/string.h>
|
2011-09-27 05:44:27 +00:00
|
|
|
#include <net/netlink.h>
|
2007-08-30 07:36:14 +00:00
|
|
|
|
2007-12-12 11:23:36 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2007-08-30 07:36:14 +00:00
|
|
|
static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
|
|
|
|
unsigned int keylen)
|
|
|
|
{
|
|
|
|
unsigned long alignmask = crypto_aead_alignmask(tfm);
|
|
|
|
int ret;
|
|
|
|
u8 *buffer, *alignbuffer;
|
|
|
|
unsigned long absize;
|
|
|
|
|
|
|
|
absize = keylen + alignmask;
|
|
|
|
buffer = kmalloc(absize, GFP_ATOMIC);
|
|
|
|
if (!buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
|
|
|
|
memcpy(alignbuffer, key, keylen);
|
2015-08-14 07:30:41 +00:00
|
|
|
ret = crypto_aead_alg(tfm)->setkey(tfm, alignbuffer, keylen);
|
2024-04-15 22:19:15 +00:00
|
|
|
kfree_sensitive(buffer);
|
2007-08-30 07:36:14 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-05-11 09:48:12 +00:00
|
|
|
int crypto_aead_setkey(struct crypto_aead *tfm,
|
|
|
|
const u8 *key, unsigned int keylen)
|
2007-08-30 07:36:14 +00:00
|
|
|
{
|
|
|
|
unsigned long alignmask = crypto_aead_alignmask(tfm);
|
2018-01-03 19:16:30 +00:00
|
|
|
int err;
|
2007-08-30 07:36:14 +00:00
|
|
|
|
|
|
|
if ((unsigned long)key & alignmask)
|
2018-01-03 19:16:30 +00:00
|
|
|
err = setkey_unaligned(tfm, key, keylen);
|
|
|
|
else
|
|
|
|
err = crypto_aead_alg(tfm)->setkey(tfm, key, keylen);
|
|
|
|
|
crypto: aead - set CRYPTO_TFM_NEED_KEY if ->setkey() fails
Some algorithms have a ->setkey() method that is not atomic, in the
sense that setting a key can fail after changes were already made to the
tfm context. In this case, if a key was already set the tfm can end up
in a state that corresponds to neither the old key nor the new key.
For example, in gcm.c, if the kzalloc() fails due to lack of memory,
then the CTR part of GCM will have the new key but GHASH will not.
It's not feasible to make all ->setkey() methods atomic, especially ones
that have to key multiple sub-tfms. Therefore, make the crypto API set
CRYPTO_TFM_NEED_KEY if ->setkey() fails, to prevent the tfm from being
used until a new key is set.
[Cc stable mainly because when introducing the NEED_KEY flag I changed
AF_ALG to rely on it; and unlike in-kernel crypto API users, AF_ALG
previously didn't have this problem. So these "incompletely keyed"
states became theoretically accessible via AF_ALG -- though, the
opportunities for causing real mischief seem pretty limited.]
Fixes: dc26c17f743a ("crypto: aead - prevent using AEADs without setting key")
Cc: <stable@vger.kernel.org> # v4.16+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-01-07 02:47:44 +00:00
|
|
|
if (unlikely(err)) {
|
|
|
|
crypto_aead_set_flags(tfm, CRYPTO_TFM_NEED_KEY);
|
2018-01-03 19:16:30 +00:00
|
|
|
return err;
|
crypto: aead - set CRYPTO_TFM_NEED_KEY if ->setkey() fails
Some algorithms have a ->setkey() method that is not atomic, in the
sense that setting a key can fail after changes were already made to the
tfm context. In this case, if a key was already set the tfm can end up
in a state that corresponds to neither the old key nor the new key.
For example, in gcm.c, if the kzalloc() fails due to lack of memory,
then the CTR part of GCM will have the new key but GHASH will not.
It's not feasible to make all ->setkey() methods atomic, especially ones
that have to key multiple sub-tfms. Therefore, make the crypto API set
CRYPTO_TFM_NEED_KEY if ->setkey() fails, to prevent the tfm from being
used until a new key is set.
[Cc stable mainly because when introducing the NEED_KEY flag I changed
AF_ALG to rely on it; and unlike in-kernel crypto API users, AF_ALG
previously didn't have this problem. So these "incompletely keyed"
states became theoretically accessible via AF_ALG -- though, the
opportunities for causing real mischief seem pretty limited.]
Fixes: dc26c17f743a ("crypto: aead - prevent using AEADs without setting key")
Cc: <stable@vger.kernel.org> # v4.16+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-01-07 02:47:44 +00:00
|
|
|
}
|
2007-08-30 07:36:14 +00:00
|
|
|
|
2018-01-03 19:16:30 +00:00
|
|
|
crypto_aead_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
|
|
|
|
return 0;
|
2007-08-30 07:36:14 +00:00
|
|
|
}
|
2015-05-11 09:48:12 +00:00
|
|
|
EXPORT_SYMBOL_GPL(crypto_aead_setkey);
|
2007-08-30 07:36:14 +00:00
|
|
|
|
2007-12-02 07:49:21 +00:00
|
|
|
int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2019-08-09 15:51:07 +00:00
|
|
|
if ((!authsize && crypto_aead_maxauthsize(tfm)) ||
|
|
|
|
authsize > crypto_aead_maxauthsize(tfm))
|
2007-12-02 07:49:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2015-08-14 07:30:41 +00:00
|
|
|
if (crypto_aead_alg(tfm)->setauthsize) {
|
|
|
|
err = crypto_aead_alg(tfm)->setauthsize(tfm, authsize);
|
2007-12-02 07:49:21 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-11 09:48:12 +00:00
|
|
|
tfm->authsize = authsize;
|
2007-12-02 07:49:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_aead_setauthsize);
|
|
|
|
|
2019-06-03 05:45:16 +00:00
|
|
|
int crypto_aead_encrypt(struct aead_request *req)
|
|
|
|
{
|
|
|
|
struct crypto_aead *aead = crypto_aead_reqtfm(req);
|
2023-02-16 10:35:11 +00:00
|
|
|
|
2019-06-03 05:45:16 +00:00
|
|
|
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
|
crypto: remove CONFIG_CRYPTO_STATS
Remove support for the "Crypto usage statistics" feature
(CONFIG_CRYPTO_STATS). This feature does not appear to have ever been
used, and it is harmful because it significantly reduces performance and
is a large maintenance burden.
Covering each of these points in detail:
1. Feature is not being used
Since these generic crypto statistics are only readable using netlink,
it's fairly straightforward to look for programs that use them. I'm
unable to find any evidence that any such programs exist. For example,
Debian Code Search returns no hits except the kernel header and kernel
code itself and translations of the kernel header:
https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1
The patch series that added this feature in 2018
(https://lore.kernel.org/linux-crypto/1537351855-16618-1-git-send-email-clabbe@baylibre.com/)
said "The goal is to have an ifconfig for crypto device." This doesn't
appear to have happened.
It's not clear that there is real demand for crypto statistics. Just
because the kernel provides other types of statistics such as I/O and
networking statistics and some people find those useful does not mean
that crypto statistics are useful too.
Further evidence that programs are not using CONFIG_CRYPTO_STATS is that
it was able to be disabled in RHEL and Fedora as a bug fix
(https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).
Even further evidence comes from the fact that there are and have been
bugs in how the stats work, but they were never reported. For example,
before Linux v6.7 hash stats were double-counted in most cases.
There has also never been any documentation for this feature, so it
might be hard to use even if someone wanted to.
2. CONFIG_CRYPTO_STATS significantly reduces performance
Enabling CONFIG_CRYPTO_STATS significantly reduces the performance of
the crypto API, even if no program ever retrieves the statistics. This
primarily affects systems with a large number of CPUs. For example,
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576 reported
that Lustre client encryption performance improved from 21.7GB/s to
48.2GB/s by disabling CONFIG_CRYPTO_STATS.
It can be argued that this means that CONFIG_CRYPTO_STATS should be
optimized with per-cpu counters similar to many of the networking
counters. But no one has done this in 5+ years. This is consistent
with the fact that the feature appears to be unused, so there seems to
be little interest in improving it as opposed to just disabling it.
It can be argued that because CONFIG_CRYPTO_STATS is off by default,
performance doesn't matter. But Linux distros tend to error on the side
of enabling options. The option is enabled in Ubuntu and Arch Linux,
and until recently was enabled in RHEL and Fedora (see above). So, even
just having the option available is harmful to users.
3. CONFIG_CRYPTO_STATS is a large maintenance burden
There are over 1000 lines of code associated with CONFIG_CRYPTO_STATS,
spread among 32 files. It significantly complicates much of the
implementation of the crypto API. After the initial submission, many
fixes and refactorings have consumed effort of multiple people to keep
this feature "working". We should be spending this effort elsewhere.
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-03-13 03:48:21 +00:00
|
|
|
return -ENOKEY;
|
2023-02-16 10:35:11 +00:00
|
|
|
|
crypto: remove CONFIG_CRYPTO_STATS
Remove support for the "Crypto usage statistics" feature
(CONFIG_CRYPTO_STATS). This feature does not appear to have ever been
used, and it is harmful because it significantly reduces performance and
is a large maintenance burden.
Covering each of these points in detail:
1. Feature is not being used
Since these generic crypto statistics are only readable using netlink,
it's fairly straightforward to look for programs that use them. I'm
unable to find any evidence that any such programs exist. For example,
Debian Code Search returns no hits except the kernel header and kernel
code itself and translations of the kernel header:
https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1
The patch series that added this feature in 2018
(https://lore.kernel.org/linux-crypto/1537351855-16618-1-git-send-email-clabbe@baylibre.com/)
said "The goal is to have an ifconfig for crypto device." This doesn't
appear to have happened.
It's not clear that there is real demand for crypto statistics. Just
because the kernel provides other types of statistics such as I/O and
networking statistics and some people find those useful does not mean
that crypto statistics are useful too.
Further evidence that programs are not using CONFIG_CRYPTO_STATS is that
it was able to be disabled in RHEL and Fedora as a bug fix
(https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).
Even further evidence comes from the fact that there are and have been
bugs in how the stats work, but they were never reported. For example,
before Linux v6.7 hash stats were double-counted in most cases.
There has also never been any documentation for this feature, so it
might be hard to use even if someone wanted to.
2. CONFIG_CRYPTO_STATS significantly reduces performance
Enabling CONFIG_CRYPTO_STATS significantly reduces the performance of
the crypto API, even if no program ever retrieves the statistics. This
primarily affects systems with a large number of CPUs. For example,
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576 reported
that Lustre client encryption performance improved from 21.7GB/s to
48.2GB/s by disabling CONFIG_CRYPTO_STATS.
It can be argued that this means that CONFIG_CRYPTO_STATS should be
optimized with per-cpu counters similar to many of the networking
counters. But no one has done this in 5+ years. This is consistent
with the fact that the feature appears to be unused, so there seems to
be little interest in improving it as opposed to just disabling it.
It can be argued that because CONFIG_CRYPTO_STATS is off by default,
performance doesn't matter. But Linux distros tend to error on the side
of enabling options. The option is enabled in Ubuntu and Arch Linux,
and until recently was enabled in RHEL and Fedora (see above). So, even
just having the option available is harmful to users.
3. CONFIG_CRYPTO_STATS is a large maintenance burden
There are over 1000 lines of code associated with CONFIG_CRYPTO_STATS,
spread among 32 files. It significantly complicates much of the
implementation of the crypto API. After the initial submission, many
fixes and refactorings have consumed effort of multiple people to keep
this feature "working". We should be spending this effort elsewhere.
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-03-13 03:48:21 +00:00
|
|
|
return crypto_aead_alg(aead)->encrypt(req);
|
2019-06-03 05:45:16 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_aead_encrypt);
|
|
|
|
|
|
|
|
int crypto_aead_decrypt(struct aead_request *req)
|
|
|
|
{
|
|
|
|
struct crypto_aead *aead = crypto_aead_reqtfm(req);
|
2023-02-16 10:35:11 +00:00
|
|
|
|
2019-06-03 05:45:16 +00:00
|
|
|
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
|
crypto: remove CONFIG_CRYPTO_STATS
Remove support for the "Crypto usage statistics" feature
(CONFIG_CRYPTO_STATS). This feature does not appear to have ever been
used, and it is harmful because it significantly reduces performance and
is a large maintenance burden.
Covering each of these points in detail:
1. Feature is not being used
Since these generic crypto statistics are only readable using netlink,
it's fairly straightforward to look for programs that use them. I'm
unable to find any evidence that any such programs exist. For example,
Debian Code Search returns no hits except the kernel header and kernel
code itself and translations of the kernel header:
https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1
The patch series that added this feature in 2018
(https://lore.kernel.org/linux-crypto/1537351855-16618-1-git-send-email-clabbe@baylibre.com/)
said "The goal is to have an ifconfig for crypto device." This doesn't
appear to have happened.
It's not clear that there is real demand for crypto statistics. Just
because the kernel provides other types of statistics such as I/O and
networking statistics and some people find those useful does not mean
that crypto statistics are useful too.
Further evidence that programs are not using CONFIG_CRYPTO_STATS is that
it was able to be disabled in RHEL and Fedora as a bug fix
(https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).
Even further evidence comes from the fact that there are and have been
bugs in how the stats work, but they were never reported. For example,
before Linux v6.7 hash stats were double-counted in most cases.
There has also never been any documentation for this feature, so it
might be hard to use even if someone wanted to.
2. CONFIG_CRYPTO_STATS significantly reduces performance
Enabling CONFIG_CRYPTO_STATS significantly reduces the performance of
the crypto API, even if no program ever retrieves the statistics. This
primarily affects systems with a large number of CPUs. For example,
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576 reported
that Lustre client encryption performance improved from 21.7GB/s to
48.2GB/s by disabling CONFIG_CRYPTO_STATS.
It can be argued that this means that CONFIG_CRYPTO_STATS should be
optimized with per-cpu counters similar to many of the networking
counters. But no one has done this in 5+ years. This is consistent
with the fact that the feature appears to be unused, so there seems to
be little interest in improving it as opposed to just disabling it.
It can be argued that because CONFIG_CRYPTO_STATS is off by default,
performance doesn't matter. But Linux distros tend to error on the side
of enabling options. The option is enabled in Ubuntu and Arch Linux,
and until recently was enabled in RHEL and Fedora (see above). So, even
just having the option available is harmful to users.
3. CONFIG_CRYPTO_STATS is a large maintenance burden
There are over 1000 lines of code associated with CONFIG_CRYPTO_STATS,
spread among 32 files. It significantly complicates much of the
implementation of the crypto API. After the initial submission, many
fixes and refactorings have consumed effort of multiple people to keep
this feature "working". We should be spending this effort elsewhere.
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-03-13 03:48:21 +00:00
|
|
|
return -ENOKEY;
|
|
|
|
|
|
|
|
if (req->cryptlen < crypto_aead_authsize(aead))
|
|
|
|
return -EINVAL;
|
2023-02-16 10:35:11 +00:00
|
|
|
|
crypto: remove CONFIG_CRYPTO_STATS
Remove support for the "Crypto usage statistics" feature
(CONFIG_CRYPTO_STATS). This feature does not appear to have ever been
used, and it is harmful because it significantly reduces performance and
is a large maintenance burden.
Covering each of these points in detail:
1. Feature is not being used
Since these generic crypto statistics are only readable using netlink,
it's fairly straightforward to look for programs that use them. I'm
unable to find any evidence that any such programs exist. For example,
Debian Code Search returns no hits except the kernel header and kernel
code itself and translations of the kernel header:
https://codesearch.debian.net/search?q=CRYPTOCFGA_STAT&literal=1&perpkg=1
The patch series that added this feature in 2018
(https://lore.kernel.org/linux-crypto/1537351855-16618-1-git-send-email-clabbe@baylibre.com/)
said "The goal is to have an ifconfig for crypto device." This doesn't
appear to have happened.
It's not clear that there is real demand for crypto statistics. Just
because the kernel provides other types of statistics such as I/O and
networking statistics and some people find those useful does not mean
that crypto statistics are useful too.
Further evidence that programs are not using CONFIG_CRYPTO_STATS is that
it was able to be disabled in RHEL and Fedora as a bug fix
(https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2947).
Even further evidence comes from the fact that there are and have been
bugs in how the stats work, but they were never reported. For example,
before Linux v6.7 hash stats were double-counted in most cases.
There has also never been any documentation for this feature, so it
might be hard to use even if someone wanted to.
2. CONFIG_CRYPTO_STATS significantly reduces performance
Enabling CONFIG_CRYPTO_STATS significantly reduces the performance of
the crypto API, even if no program ever retrieves the statistics. This
primarily affects systems with a large number of CPUs. For example,
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2039576 reported
that Lustre client encryption performance improved from 21.7GB/s to
48.2GB/s by disabling CONFIG_CRYPTO_STATS.
It can be argued that this means that CONFIG_CRYPTO_STATS should be
optimized with per-cpu counters similar to many of the networking
counters. But no one has done this in 5+ years. This is consistent
with the fact that the feature appears to be unused, so there seems to
be little interest in improving it as opposed to just disabling it.
It can be argued that because CONFIG_CRYPTO_STATS is off by default,
performance doesn't matter. But Linux distros tend to error on the side
of enabling options. The option is enabled in Ubuntu and Arch Linux,
and until recently was enabled in RHEL and Fedora (see above). So, even
just having the option available is harmful to users.
3. CONFIG_CRYPTO_STATS is a large maintenance burden
There are over 1000 lines of code associated with CONFIG_CRYPTO_STATS,
spread among 32 files. It significantly complicates much of the
implementation of the crypto API. After the initial submission, many
fixes and refactorings have consumed effort of multiple people to keep
this feature "working". We should be spending this effort elsewhere.
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-03-13 03:48:21 +00:00
|
|
|
return crypto_aead_alg(aead)->decrypt(req);
|
2019-06-03 05:45:16 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_aead_decrypt);
|
|
|
|
|
2015-05-28 14:07:53 +00:00
|
|
|
static void crypto_aead_exit_tfm(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
struct crypto_aead *aead = __crypto_aead_cast(tfm);
|
|
|
|
struct aead_alg *alg = crypto_aead_alg(aead);
|
|
|
|
|
|
|
|
alg->exit(aead);
|
|
|
|
}
|
|
|
|
|
2015-05-21 07:11:08 +00:00
|
|
|
static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
struct crypto_aead *aead = __crypto_aead_cast(tfm);
|
|
|
|
struct aead_alg *alg = crypto_aead_alg(aead);
|
|
|
|
|
2018-01-03 19:16:30 +00:00
|
|
|
crypto_aead_set_flags(aead, CRYPTO_TFM_NEED_KEY);
|
|
|
|
|
2015-05-21 07:11:08 +00:00
|
|
|
aead->authsize = alg->maxauthsize;
|
|
|
|
|
2015-05-28 14:07:53 +00:00
|
|
|
if (alg->exit)
|
|
|
|
aead->base.exit = crypto_aead_exit_tfm;
|
|
|
|
|
|
|
|
if (alg->init)
|
|
|
|
return alg->init(aead);
|
|
|
|
|
2015-05-21 07:11:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-16 10:35:28 +00:00
|
|
|
static int __maybe_unused crypto_aead_report(
|
|
|
|
struct sk_buff *skb, struct crypto_alg *alg)
|
2015-05-21 07:11:08 +00:00
|
|
|
{
|
|
|
|
struct crypto_report_aead raead;
|
|
|
|
struct aead_alg *aead = container_of(alg, struct aead_alg, base);
|
|
|
|
|
2018-11-03 21:56:03 +00:00
|
|
|
memset(&raead, 0, sizeof(raead));
|
|
|
|
|
|
|
|
strscpy(raead.type, "aead", sizeof(raead.type));
|
|
|
|
strscpy(raead.geniv, "<none>", sizeof(raead.geniv));
|
2015-05-21 07:11:08 +00:00
|
|
|
|
|
|
|
raead.blocksize = alg->cra_blocksize;
|
|
|
|
raead.maxauthsize = aead->maxauthsize;
|
|
|
|
raead.ivsize = aead->ivsize;
|
|
|
|
|
2018-11-03 21:56:03 +00:00
|
|
|
return nla_put(skb, CRYPTOCFGA_REPORT_AEAD, sizeof(raead), &raead);
|
2015-05-21 07:11:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
|
2016-12-31 15:56:23 +00:00
|
|
|
__maybe_unused;
|
2015-05-21 07:11:08 +00:00
|
|
|
static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
|
|
|
|
{
|
|
|
|
struct aead_alg *aead = container_of(alg, struct aead_alg, base);
|
|
|
|
|
|
|
|
seq_printf(m, "type : aead\n");
|
|
|
|
seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
|
|
|
|
"yes" : "no");
|
|
|
|
seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
|
|
|
|
seq_printf(m, "ivsize : %u\n", aead->ivsize);
|
|
|
|
seq_printf(m, "maxauthsize : %u\n", aead->maxauthsize);
|
|
|
|
seq_printf(m, "geniv : <none>\n");
|
|
|
|
}
|
|
|
|
|
2015-07-08 23:17:17 +00:00
|
|
|
static void crypto_aead_free_instance(struct crypto_instance *inst)
|
|
|
|
{
|
|
|
|
struct aead_instance *aead = aead_instance(inst);
|
|
|
|
|
|
|
|
aead->free(aead);
|
|
|
|
}
|
|
|
|
|
2015-08-14 07:30:41 +00:00
|
|
|
static const struct crypto_type crypto_aead_type = {
|
2015-05-21 07:11:08 +00:00
|
|
|
.extsize = crypto_alg_extsize,
|
|
|
|
.init_tfm = crypto_aead_init_tfm,
|
2015-07-08 23:17:17 +00:00
|
|
|
.free = crypto_aead_free_instance,
|
2015-05-21 07:11:08 +00:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
.show = crypto_aead_show,
|
|
|
|
#endif
|
2023-05-02 08:02:33 +00:00
|
|
|
#if IS_ENABLED(CONFIG_CRYPTO_USER)
|
2015-05-21 07:11:08 +00:00
|
|
|
.report = crypto_aead_report,
|
2023-02-16 10:35:11 +00:00
|
|
|
#endif
|
2015-05-21 07:11:08 +00:00
|
|
|
.maskclear = ~CRYPTO_ALG_TYPE_MASK,
|
|
|
|
.maskset = CRYPTO_ALG_TYPE_MASK,
|
|
|
|
.type = CRYPTO_ALG_TYPE_AEAD,
|
|
|
|
.tfmsize = offsetof(struct crypto_aead, base),
|
|
|
|
};
|
|
|
|
|
2020-01-03 03:58:46 +00:00
|
|
|
int crypto_grab_aead(struct crypto_aead_spawn *spawn,
|
|
|
|
struct crypto_instance *inst,
|
|
|
|
const char *name, u32 type, u32 mask)
|
2007-12-12 11:24:27 +00:00
|
|
|
{
|
2015-05-11 09:48:12 +00:00
|
|
|
spawn->base.frontend = &crypto_aead_type;
|
2020-01-03 03:58:48 +00:00
|
|
|
return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
|
2007-12-12 11:24:27 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_grab_aead);
|
|
|
|
|
|
|
|
struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask)
|
|
|
|
{
|
2015-05-11 09:48:12 +00:00
|
|
|
return crypto_alloc_tfm(alg_name, &crypto_aead_type, type, mask);
|
2007-12-12 11:24:27 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_alloc_aead);
|
|
|
|
|
2023-09-14 08:28:21 +00:00
|
|
|
int crypto_has_aead(const char *alg_name, u32 type, u32 mask)
|
|
|
|
{
|
|
|
|
return crypto_type_has_alg(alg_name, &crypto_aead_type, type, mask);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_has_aead);
|
|
|
|
|
2015-05-21 07:11:08 +00:00
|
|
|
static int aead_prepare_alg(struct aead_alg *alg)
|
|
|
|
{
|
|
|
|
struct crypto_alg *base = &alg->base;
|
|
|
|
|
2016-07-12 05:17:33 +00:00
|
|
|
if (max3(alg->maxauthsize, alg->ivsize, alg->chunksize) >
|
|
|
|
PAGE_SIZE / 8)
|
2015-05-21 07:11:08 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-07-12 05:17:33 +00:00
|
|
|
if (!alg->chunksize)
|
|
|
|
alg->chunksize = base->cra_blocksize;
|
|
|
|
|
2015-08-14 07:30:41 +00:00
|
|
|
base->cra_type = &crypto_aead_type;
|
2015-05-21 07:11:08 +00:00
|
|
|
base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
|
|
|
|
base->cra_flags |= CRYPTO_ALG_TYPE_AEAD;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int crypto_register_aead(struct aead_alg *alg)
|
|
|
|
{
|
|
|
|
struct crypto_alg *base = &alg->base;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = aead_prepare_alg(alg);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return crypto_register_alg(base);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_register_aead);
|
|
|
|
|
2015-05-28 14:07:57 +00:00
|
|
|
void crypto_unregister_aead(struct aead_alg *alg)
|
2015-05-21 07:11:08 +00:00
|
|
|
{
|
2015-05-28 14:07:57 +00:00
|
|
|
crypto_unregister_alg(&alg->base);
|
2015-05-21 07:11:08 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_aead);
|
|
|
|
|
2015-05-28 14:07:59 +00:00
|
|
|
int crypto_register_aeads(struct aead_alg *algs, int count)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
ret = crypto_register_aead(&algs[i]);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
for (--i; i >= 0; --i)
|
|
|
|
crypto_unregister_aead(&algs[i]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_register_aeads);
|
|
|
|
|
|
|
|
void crypto_unregister_aeads(struct aead_alg *algs, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = count - 1; i >= 0; --i)
|
|
|
|
crypto_unregister_aead(&algs[i]);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_aeads);
|
|
|
|
|
2015-05-21 07:11:08 +00:00
|
|
|
int aead_register_instance(struct crypto_template *tmpl,
|
|
|
|
struct aead_instance *inst)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2020-01-03 04:04:40 +00:00
|
|
|
if (WARN_ON(!inst->free))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-05-21 07:11:08 +00:00
|
|
|
err = aead_prepare_alg(&inst->alg);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return crypto_register_instance(tmpl, aead_crypto_instance(inst));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(aead_register_instance);
|
|
|
|
|
2007-08-30 07:36:14 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Authenticated Encryption with Associated Data (AEAD)");
|