2019-05-27 14:55:01 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Scatterlist Cryptographic API.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
|
|
|
|
* Copyright (c) 2002 David S. Miller (davem@redhat.com)
|
2005-11-05 13:58:14 +08:00
|
|
|
* Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
|
2007-10-20 05:07:36 +08:00
|
|
|
* and Nettle, by Niels Möller.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
#ifndef _LINUX_CRYPTO_H
|
|
|
|
#define _LINUX_CRYPTO_H
|
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
2011-11-24 09:12:59 +08:00
|
|
|
#include <linux/bug.h>
|
2020-06-18 15:00:22 +08:00
|
|
|
#include <linux/refcount.h>
|
2006-08-21 19:03:52 +08:00
|
|
|
#include <linux/slab.h>
|
2017-10-18 15:00:38 +08:00
|
|
|
#include <linux/completion.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-11-21 09:05:53 +08:00
|
|
|
/*
|
|
|
|
* Autoloaded crypto modules should only use a prefixed name to avoid allowing
|
|
|
|
* arbitrary modules to be loaded. Loading from userspace may still need the
|
|
|
|
* unprefixed names, so retains those aliases as well.
|
|
|
|
* This uses __MODULE_INFO directly instead of MODULE_ALIAS because pre-4.3
|
|
|
|
* gcc (e.g. avr32 toolchain) uses __LINE__ for uniqueness, and this macro
|
|
|
|
* expands twice on the same line. Instead, use a separate base name for the
|
|
|
|
* alias.
|
|
|
|
*/
|
|
|
|
#define MODULE_ALIAS_CRYPTO(name) \
|
|
|
|
__MODULE_INFO(alias, alias_userspace, name); \
|
|
|
|
__MODULE_INFO(alias, alias_crypto, "crypto-" name)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Algorithm masks and types.
|
|
|
|
*/
|
2006-08-06 19:23:26 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_MASK 0x0000000f
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_CIPHER 0x00000001
|
2008-05-14 20:41:47 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_COMPRESS 0x00000002
|
|
|
|
#define CRYPTO_ALG_TYPE_AEAD 0x00000003
|
2016-07-12 13:17:31 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_SKCIPHER 0x00000005
|
2016-06-23 00:49:13 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_KPP 0x00000008
|
2016-10-21 20:19:47 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_ACOMPRESS 0x0000000a
|
2016-10-21 20:19:48 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000b
|
2008-08-14 20:15:52 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_RNG 0x0000000c
|
2015-06-17 01:30:55 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d
|
2016-06-02 20:28:55 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_HASH 0x0000000e
|
|
|
|
#define CRYPTO_ALG_TYPE_SHASH 0x0000000e
|
|
|
|
#define CRYPTO_ALG_TYPE_AHASH 0x0000000f
|
2006-08-19 20:24:23 +08:00
|
|
|
|
|
|
|
#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
|
2016-06-02 20:28:55 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e
|
2016-10-21 20:19:48 +08:00
|
|
|
#define CRYPTO_ALG_TYPE_ACOMPRESS_MASK 0x0000000e
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-06 19:23:26 +08:00
|
|
|
#define CRYPTO_ALG_LARVAL 0x00000010
|
2006-09-21 09:39:29 +08:00
|
|
|
#define CRYPTO_ALG_DEAD 0x00000020
|
|
|
|
#define CRYPTO_ALG_DYING 0x00000040
|
2006-08-06 21:12:59 +08:00
|
|
|
#define CRYPTO_ALG_ASYNC 0x00000080
|
2006-08-06 19:23:26 +08:00
|
|
|
|
2006-08-26 16:34:10 +08:00
|
|
|
/*
|
2020-07-10 14:20:39 +08:00
|
|
|
* Set if the algorithm (or an algorithm which it uses) requires another
|
|
|
|
* algorithm of the same type to handle corner cases.
|
2006-08-26 16:34:10 +08:00
|
|
|
*/
|
|
|
|
#define CRYPTO_ALG_NEED_FALLBACK 0x00000100
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
/*
|
|
|
|
* Set if the algorithm has passed automated run-time testing. Note that
|
|
|
|
* if there is no run-time testing for a given algorithm it is considered
|
|
|
|
* to have passed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CRYPTO_ALG_TESTED 0x00000400
|
|
|
|
|
2011-09-27 13:21:26 +08:00
|
|
|
/*
|
2016-11-30 21:16:08 +08:00
|
|
|
* Set if the algorithm is an instance that is built from templates.
|
2011-09-27 13:21:26 +08:00
|
|
|
*/
|
|
|
|
#define CRYPTO_ALG_INSTANCE 0x00000800
|
|
|
|
|
2011-11-01 20:39:56 +08:00
|
|
|
/* Set this bit if the algorithm provided is hardware accelerated but
|
|
|
|
* not available to userspace via instruction set or so.
|
|
|
|
*/
|
|
|
|
#define CRYPTO_ALG_KERN_DRIVER_ONLY 0x00001000
|
|
|
|
|
2015-03-31 03:55:52 +08:00
|
|
|
/*
|
|
|
|
* Mark a cipher as a service implementation only usable by another
|
|
|
|
* cipher and never by a normal user of the kernel crypto API
|
|
|
|
*/
|
|
|
|
#define CRYPTO_ALG_INTERNAL 0x00002000
|
|
|
|
|
2018-01-04 03:16:26 +08:00
|
|
|
/*
|
|
|
|
* Set if the algorithm has a ->setkey() method but can be used without
|
|
|
|
* calling it first, i.e. there is a default key.
|
|
|
|
*/
|
|
|
|
#define CRYPTO_ALG_OPTIONAL_KEY 0x00004000
|
|
|
|
|
2018-06-09 05:57:42 +08:00
|
|
|
/*
|
|
|
|
* Don't trigger module loading
|
|
|
|
*/
|
|
|
|
#define CRYPTO_NOLOAD 0x00008000
|
|
|
|
|
2020-07-10 14:20:40 +08:00
|
|
|
/*
|
|
|
|
* The algorithm may allocate memory during request processing, i.e. during
|
|
|
|
* encryption, decryption, or hashing. Users can request an algorithm with this
|
|
|
|
* flag unset if they can't handle memory allocation failures.
|
|
|
|
*
|
|
|
|
* This flag is currently only implemented for algorithms of type "skcipher",
|
|
|
|
* "aead", "ahash", "shash", and "cipher". Algorithms of other types might not
|
|
|
|
* have this flag set even if they allocate memory.
|
|
|
|
*
|
|
|
|
* In some edge cases, algorithms can allocate memory regardless of this flag.
|
|
|
|
* To avoid these cases, users must obey the following usage constraints:
|
|
|
|
* skcipher:
|
|
|
|
* - The IV buffer and all scatterlist elements must be aligned to the
|
|
|
|
* algorithm's alignmask.
|
|
|
|
* - If the data were to be divided into chunks of size
|
|
|
|
* crypto_skcipher_walksize() (with any remainder going at the end), no
|
|
|
|
* chunk can cross a page boundary or a scatterlist element boundary.
|
|
|
|
* aead:
|
|
|
|
* - The IV buffer and all scatterlist elements must be aligned to the
|
|
|
|
* algorithm's alignmask.
|
|
|
|
* - The first scatterlist element must contain all the associated data,
|
|
|
|
* and its pages must be !PageHighMem.
|
|
|
|
* - If the plaintext/ciphertext were to be divided into chunks of size
|
|
|
|
* crypto_aead_walksize() (with the remainder going at the end), no chunk
|
|
|
|
* can cross a page boundary or a scatterlist element boundary.
|
|
|
|
* ahash:
|
|
|
|
* - The result buffer must be aligned to the algorithm's alignmask.
|
|
|
|
* - crypto_ahash_finup() must not be used unless the algorithm implements
|
|
|
|
* ->finup() natively.
|
|
|
|
*/
|
|
|
|
#define CRYPTO_ALG_ALLOCATES_MEMORY 0x00010000
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Transform masks and values (for crt_flags).
|
|
|
|
*/
|
crypto: hash - prevent using keyed hashes without setting key
Currently, almost none of the keyed hash algorithms check whether a key
has been set before proceeding. Some algorithms are okay with this and
will effectively just use a key of all 0's or some other bogus default.
However, others will severely break, as demonstrated using
"hmac(sha3-512-generic)", the unkeyed use of which causes a kernel crash
via a (potentially exploitable) stack buffer overflow.
A while ago, this problem was solved for AF_ALG by pairing each hash
transform with a 'has_key' bool. However, there are still other places
in the kernel where userspace can specify an arbitrary hash algorithm by
name, and the kernel uses it as unkeyed hash without checking whether it
is really unkeyed. Examples of this include:
- KEYCTL_DH_COMPUTE, via the KDF extension
- dm-verity
- dm-crypt, via the ESSIV support
- dm-integrity, via the "internal hash" mode with no key given
- drbd (Distributed Replicated Block Device)
This bug is especially bad for KEYCTL_DH_COMPUTE as that requires no
privileges to call.
Fix the bug for all users by adding a flag CRYPTO_TFM_NEED_KEY to the
->crt_flags of each hash transform that indicates whether the transform
still needs to be keyed or not. Then, make the hash init, import, and
digest functions return -ENOKEY if the key is still needed.
The new flag also replaces the 'has_key' bool which algif_hash was
previously using, thereby simplifying the algif_hash implementation.
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2018-01-04 03:16:27 +08:00
|
|
|
#define CRYPTO_TFM_NEED_KEY 0x00000001
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CRYPTO_TFM_REQ_MASK 0x000fff00
|
2019-01-19 14:48:00 +08:00
|
|
|
#define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS 0x00000100
|
2005-09-02 08:43:05 +08:00
|
|
|
#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
|
2007-03-24 11:35:34 +08:00
|
|
|
#define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous stuff.
|
|
|
|
*/
|
2017-04-06 16:16:11 +08:00
|
|
|
#define CRYPTO_MAX_ALG_NAME 128
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-21 19:03:52 +08:00
|
|
|
/*
|
|
|
|
* The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
|
|
|
|
* declaration) is used to ensure that the crypto_tfm context structure is
|
|
|
|
* aligned correctly for the given architecture so that there are no alignment
|
crypto - shash: reduce minimum alignment of shash_desc structure
Unlike many other structure types defined in the crypto API, the
'shash_desc' structure is permitted to live on the stack, which
implies its contents may not be accessed by DMA masters. (This is
due to the fact that the stack may be located in the vmalloc area,
which requires a different virtual-to-physical translation than the
one implemented by the DMA subsystem)
Our definition of CRYPTO_MINALIGN_ATTR is based on ARCH_KMALLOC_MINALIGN,
which may take DMA constraints into account on architectures that support
non-cache coherent DMA such as ARM and arm64. In this case, the value is
chosen to reflect the largest cacheline size in the system, in order to
ensure that explicit cache maintenance as required by non-coherent DMA
masters does not affect adjacent, unrelated slab allocations. On arm64,
this value is currently set at 128 bytes.
This means that applying CRYPTO_MINALIGN_ATTR to struct shash_desc is both
unnecessary (as it is never used for DMA), and undesirable, given that it
wastes stack space (on arm64, performing the alignment costs 112 bytes in
the worst case, and the hole between the 'tfm' and '__ctx' members takes
up another 120 bytes, resulting in an increased stack footprint of up to
232 bytes.) So instead, let's switch to the minimum SLAB alignment, which
does not take DMA constraints into account.
Note that this is a no-op for x86.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-13 17:11:35 +08:00
|
|
|
* faults for C data types. On architectures that support non-cache coherent
|
|
|
|
* DMA, such as ARM or arm64, it also takes into account the minimal alignment
|
|
|
|
* that is required to ensure that the context struct member does not share any
|
|
|
|
* cachelines with the rest of the struct. This is needed to ensure that cache
|
|
|
|
* maintenance for non-coherent DMA (cache invalidation in particular) does not
|
|
|
|
* affect data that may be accessed by the CPU concurrently.
|
2006-08-21 19:03:52 +08:00
|
|
|
*/
|
|
|
|
#define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
|
|
|
|
|
|
|
|
#define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scatterlist;
|
2007-03-24 11:35:34 +08:00
|
|
|
struct crypto_async_request;
|
2005-07-07 04:51:52 +08:00
|
|
|
struct crypto_tfm;
|
2006-08-21 22:06:54 +08:00
|
|
|
struct crypto_type;
|
2005-07-07 04:51:52 +08:00
|
|
|
|
2007-03-24 11:35:34 +08:00
|
|
|
typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
|
|
|
|
|
2014-11-12 12:27:49 +08:00
|
|
|
/**
|
|
|
|
* DOC: Block Cipher Context Data Structures
|
|
|
|
*
|
|
|
|
* These data structures define the operating context for each block cipher
|
|
|
|
* type.
|
|
|
|
*/
|
|
|
|
|
2007-03-24 11:35:34 +08:00
|
|
|
struct crypto_async_request {
|
|
|
|
struct list_head list;
|
|
|
|
crypto_completion_t complete;
|
|
|
|
void *data;
|
|
|
|
struct crypto_tfm *tfm;
|
|
|
|
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
|
2014-11-12 12:27:49 +08:00
|
|
|
/**
|
|
|
|
* DOC: Block Cipher Algorithm Definitions
|
|
|
|
*
|
|
|
|
* These data structures define modular crypto algorithm implementations,
|
|
|
|
* managed via crypto_register_alg() and crypto_unregister_alg().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct cipher_alg - single-block symmetric ciphers definition
|
|
|
|
* @cia_min_keysize: Minimum key size supported by the transformation. This is
|
|
|
|
* the smallest key length supported by this transformation
|
|
|
|
* algorithm. This must be set to one of the pre-defined
|
|
|
|
* values as this is not hardware specific. Possible values
|
|
|
|
* for this field can be found via git grep "_MIN_KEY_SIZE"
|
|
|
|
* include/crypto/
|
|
|
|
* @cia_max_keysize: Maximum key size supported by the transformation. This is
|
|
|
|
* the largest key length supported by this transformation
|
|
|
|
* algorithm. This must be set to one of the pre-defined values
|
|
|
|
* as this is not hardware specific. Possible values for this
|
|
|
|
* field can be found via git grep "_MAX_KEY_SIZE"
|
|
|
|
* include/crypto/
|
|
|
|
* @cia_setkey: Set key for the transformation. This function is used to either
|
|
|
|
* program a supplied key into the hardware or store the key in the
|
|
|
|
* transformation context for programming it later. Note that this
|
|
|
|
* function does modify the transformation context. This function
|
|
|
|
* can be called multiple times during the existence of the
|
|
|
|
* transformation object, so one must make sure the key is properly
|
|
|
|
* reprogrammed into the hardware. This function is also
|
|
|
|
* responsible for checking the key length for validity.
|
|
|
|
* @cia_encrypt: Encrypt a single block. This function is used to encrypt a
|
|
|
|
* single block of data, which must be @cra_blocksize big. This
|
|
|
|
* always operates on a full @cra_blocksize and it is not possible
|
|
|
|
* to encrypt a block of smaller size. The supplied buffers must
|
|
|
|
* therefore also be at least of @cra_blocksize size. Both the
|
|
|
|
* input and output buffers are always aligned to @cra_alignmask.
|
|
|
|
* In case either of the input or output buffer supplied by user
|
|
|
|
* of the crypto API is not aligned to @cra_alignmask, the crypto
|
|
|
|
* API will re-align the buffers. The re-alignment means that a
|
|
|
|
* new buffer will be allocated, the data will be copied into the
|
|
|
|
* new buffer, then the processing will happen on the new buffer,
|
|
|
|
* then the data will be copied back into the original buffer and
|
|
|
|
* finally the new buffer will be freed. In case a software
|
|
|
|
* fallback was put in place in the @cra_init call, this function
|
|
|
|
* might need to use the fallback if the algorithm doesn't support
|
|
|
|
* all of the key sizes. In case the key was stored in
|
|
|
|
* transformation context, the key might need to be re-programmed
|
|
|
|
* into the hardware in this function. This function shall not
|
|
|
|
* modify the transformation context, as this function may be
|
|
|
|
* called in parallel with the same transformation object.
|
|
|
|
* @cia_decrypt: Decrypt a single block. This is a reverse counterpart to
|
|
|
|
* @cia_encrypt, and the conditions are exactly the same.
|
|
|
|
*
|
|
|
|
* All fields are mandatory and must be filled.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cipher_alg {
|
|
|
|
unsigned int cia_min_keysize;
|
|
|
|
unsigned int cia_max_keysize;
|
2006-05-16 20:09:29 +08:00
|
|
|
int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
|
2006-08-13 12:16:39 +08:00
|
|
|
unsigned int keylen);
|
2006-05-16 20:09:29 +08:00
|
|
|
void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
|
|
|
|
void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2019-06-26 07:43:43 +08:00
|
|
|
/**
|
|
|
|
* struct compress_alg - compression/decompression algorithm
|
|
|
|
* @coa_compress: Compress a buffer of specified length, storing the resulting
|
|
|
|
* data in the specified buffer. Return the length of the
|
|
|
|
* compressed data in dlen.
|
|
|
|
* @coa_decompress: Decompress the source buffer, storing the uncompressed
|
|
|
|
* data in the specified buffer. The length of the data is
|
|
|
|
* returned in dlen.
|
|
|
|
*
|
|
|
|
* All fields are mandatory.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
struct compress_alg {
|
2006-05-16 20:09:29 +08:00
|
|
|
int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
|
|
|
|
unsigned int slen, u8 *dst, unsigned int *dlen);
|
|
|
|
int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
|
|
|
|
unsigned int slen, u8 *dst, unsigned int *dlen);
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2018-11-29 22:42:24 +08:00
|
|
|
#ifdef CONFIG_CRYPTO_STATS
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_aead - statistics for AEAD algorithm
|
|
|
|
* @encrypt_cnt: number of encrypt requests
|
|
|
|
* @encrypt_tlen: total data size handled by encrypt requests
|
|
|
|
* @decrypt_cnt: number of decrypt requests
|
|
|
|
* @decrypt_tlen: total data size handled by decrypt requests
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for AEAD requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_aead {
|
|
|
|
atomic64_t encrypt_cnt;
|
|
|
|
atomic64_t encrypt_tlen;
|
|
|
|
atomic64_t decrypt_cnt;
|
|
|
|
atomic64_t decrypt_tlen;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_akcipher - statistics for akcipher algorithm
|
|
|
|
* @encrypt_cnt: number of encrypt requests
|
|
|
|
* @encrypt_tlen: total data size handled by encrypt requests
|
|
|
|
* @decrypt_cnt: number of decrypt requests
|
|
|
|
* @decrypt_tlen: total data size handled by decrypt requests
|
|
|
|
* @verify_cnt: number of verify operation
|
|
|
|
* @sign_cnt: number of sign requests
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for akcipher requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_akcipher {
|
|
|
|
atomic64_t encrypt_cnt;
|
|
|
|
atomic64_t encrypt_tlen;
|
|
|
|
atomic64_t decrypt_cnt;
|
|
|
|
atomic64_t decrypt_tlen;
|
|
|
|
atomic64_t verify_cnt;
|
|
|
|
atomic64_t sign_cnt;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_cipher - statistics for cipher algorithm
|
|
|
|
* @encrypt_cnt: number of encrypt requests
|
|
|
|
* @encrypt_tlen: total data size handled by encrypt requests
|
|
|
|
* @decrypt_cnt: number of decrypt requests
|
|
|
|
* @decrypt_tlen: total data size handled by decrypt requests
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for cipher requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_cipher {
|
|
|
|
atomic64_t encrypt_cnt;
|
|
|
|
atomic64_t encrypt_tlen;
|
|
|
|
atomic64_t decrypt_cnt;
|
|
|
|
atomic64_t decrypt_tlen;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_compress - statistics for compress algorithm
|
|
|
|
* @compress_cnt: number of compress requests
|
|
|
|
* @compress_tlen: total data size handled by compress requests
|
|
|
|
* @decompress_cnt: number of decompress requests
|
|
|
|
* @decompress_tlen: total data size handled by decompress requests
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for compress requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_compress {
|
|
|
|
atomic64_t compress_cnt;
|
|
|
|
atomic64_t compress_tlen;
|
|
|
|
atomic64_t decompress_cnt;
|
|
|
|
atomic64_t decompress_tlen;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_hash - statistics for has algorithm
|
|
|
|
* @hash_cnt: number of hash requests
|
|
|
|
* @hash_tlen: total data size hashed
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for hash requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_hash {
|
|
|
|
atomic64_t hash_cnt;
|
|
|
|
atomic64_t hash_tlen;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_kpp - statistics for KPP algorithm
|
|
|
|
* @setsecret_cnt: number of setsecrey operation
|
|
|
|
* @generate_public_key_cnt: number of generate_public_key operation
|
|
|
|
* @compute_shared_secret_cnt: number of compute_shared_secret operation
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for KPP requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_kpp {
|
|
|
|
atomic64_t setsecret_cnt;
|
|
|
|
atomic64_t generate_public_key_cnt;
|
|
|
|
atomic64_t compute_shared_secret_cnt;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct crypto_istat_rng: statistics for RNG algorithm
|
|
|
|
* @generate_cnt: number of RNG generate requests
|
|
|
|
* @generate_tlen: total data size of generated data by the RNG
|
|
|
|
* @seed_cnt: number of times the RNG was seeded
|
2018-11-29 22:42:25 +08:00
|
|
|
* @err_cnt: number of error for RNG requests
|
2018-11-29 22:42:24 +08:00
|
|
|
*/
|
|
|
|
struct crypto_istat_rng {
|
|
|
|
atomic64_t generate_cnt;
|
|
|
|
atomic64_t generate_tlen;
|
|
|
|
atomic64_t seed_cnt;
|
2018-11-29 22:42:25 +08:00
|
|
|
atomic64_t err_cnt;
|
2018-11-29 22:42:24 +08:00
|
|
|
};
|
|
|
|
#endif /* CONFIG_CRYPTO_STATS */
|
2008-08-14 20:15:52 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define cra_cipher cra_u.cipher
|
|
|
|
#define cra_compress cra_u.compress
|
|
|
|
|
2014-11-12 12:27:49 +08:00
|
|
|
/**
|
|
|
|
* struct crypto_alg - definition of a cryptograpic cipher algorithm
|
|
|
|
* @cra_flags: Flags describing this transformation. See include/linux/crypto.h
|
|
|
|
* CRYPTO_ALG_* flags for the flags which go in here. Those are
|
|
|
|
* used for fine-tuning the description of the transformation
|
|
|
|
* algorithm.
|
|
|
|
* @cra_blocksize: Minimum block size of this transformation. The size in bytes
|
|
|
|
* of the smallest possible unit which can be transformed with
|
|
|
|
* this algorithm. The users must respect this value.
|
|
|
|
* In case of HASH transformation, it is possible for a smaller
|
|
|
|
* block than @cra_blocksize to be passed to the crypto API for
|
|
|
|
* transformation, in case of any other transformation type, an
|
|
|
|
* error will be returned upon any attempt to transform smaller
|
|
|
|
* than @cra_blocksize chunks.
|
|
|
|
* @cra_ctxsize: Size of the operational context of the transformation. This
|
|
|
|
* value informs the kernel crypto API about the memory size
|
|
|
|
* needed to be allocated for the transformation context.
|
|
|
|
* @cra_alignmask: Alignment mask for the input and output data buffer. The data
|
|
|
|
* buffer containing the input data for the algorithm must be
|
|
|
|
* aligned to this alignment mask. The data buffer for the
|
|
|
|
* output data must be aligned to this alignment mask. Note that
|
|
|
|
* the Crypto API will do the re-alignment in software, but
|
|
|
|
* only under special conditions and there is a performance hit.
|
|
|
|
* The re-alignment happens at these occasions for different
|
|
|
|
* @cra_u types: cipher -- For both input data and output data
|
|
|
|
* buffer; ahash -- For output hash destination buf; shash --
|
|
|
|
* For output hash destination buf.
|
|
|
|
* This is needed on hardware which is flawed by design and
|
|
|
|
* cannot pick data from arbitrary addresses.
|
|
|
|
* @cra_priority: Priority of this transformation implementation. In case
|
|
|
|
* multiple transformations with same @cra_name are available to
|
|
|
|
* the Crypto API, the kernel will use the one with highest
|
|
|
|
* @cra_priority.
|
|
|
|
* @cra_name: Generic name (usable by multiple implementations) of the
|
|
|
|
* transformation algorithm. This is the name of the transformation
|
|
|
|
* itself. This field is used by the kernel when looking up the
|
|
|
|
* providers of particular transformation.
|
|
|
|
* @cra_driver_name: Unique name of the transformation provider. This is the
|
|
|
|
* name of the provider of the transformation. This can be any
|
|
|
|
* arbitrary value, but in the usual case, this contains the
|
|
|
|
* name of the chip or provider and the name of the
|
|
|
|
* transformation algorithm.
|
|
|
|
* @cra_type: Type of the cryptographic transformation. This is a pointer to
|
|
|
|
* struct crypto_type, which implements callbacks common for all
|
crypto: skcipher - remove the "blkcipher" algorithm type
Now that all "blkcipher" algorithms have been converted to "skcipher",
remove the blkcipher algorithm type.
The skcipher (symmetric key cipher) algorithm type was introduced a few
years ago to replace both blkcipher and ablkcipher (synchronous and
asynchronous block cipher). The advantages of skcipher include:
- A much less confusing name, since none of these algorithm types have
ever actually been for raw block ciphers, but rather for all
length-preserving encryption modes including block cipher modes of
operation, stream ciphers, and other length-preserving modes.
- It unified blkcipher and ablkcipher into a single algorithm type
which supports both synchronous and asynchronous implementations.
Note, blkcipher already operated only on scatterlists, so the fact
that skcipher does too isn't a regression in functionality.
- Better type safety by using struct skcipher_alg, struct
crypto_skcipher, etc. instead of crypto_alg, crypto_tfm, etc.
- It sometimes simplifies the implementations of algorithms.
Also, the blkcipher API was no longer being tested.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-10-26 03:41:12 +08:00
|
|
|
* transformation types. There are multiple options, such as
|
|
|
|
* &crypto_skcipher_type, &crypto_ahash_type, &crypto_rng_type.
|
2014-11-12 12:27:49 +08:00
|
|
|
* This field might be empty. In that case, there are no common
|
|
|
|
* callbacks. This is the case for: cipher, compress, shash.
|
|
|
|
* @cra_u: Callbacks implementing the transformation. This is a union of
|
|
|
|
* multiple structures. Depending on the type of transformation selected
|
|
|
|
* by @cra_type and @cra_flags above, the associated structure must be
|
|
|
|
* filled with callbacks. This field might be empty. This is the case
|
|
|
|
* for ahash, shash.
|
|
|
|
* @cra_init: Initialize the cryptographic transformation object. This function
|
|
|
|
* is used to initialize the cryptographic transformation object.
|
|
|
|
* This function is called only once at the instantiation time, right
|
|
|
|
* after the transformation context was allocated. In case the
|
|
|
|
* cryptographic hardware has some special requirements which need to
|
|
|
|
* be handled by software, this function shall check for the precise
|
|
|
|
* requirement of the transformation and put any software fallbacks
|
|
|
|
* in place.
|
|
|
|
* @cra_exit: Deinitialize the cryptographic transformation object. This is a
|
|
|
|
* counterpart to @cra_init, used to remove various changes set in
|
|
|
|
* @cra_init.
|
2018-03-15 06:15:52 +08:00
|
|
|
* @cra_u.cipher: Union member which contains a single-block symmetric cipher
|
|
|
|
* definition. See @struct @cipher_alg.
|
|
|
|
* @cra_u.compress: Union member which contains a (de)compression algorithm.
|
|
|
|
* See @struct @compress_alg.
|
2014-11-12 12:27:49 +08:00
|
|
|
* @cra_module: Owner of this transformation implementation. Set to THIS_MODULE
|
|
|
|
* @cra_list: internally used
|
|
|
|
* @cra_users: internally used
|
|
|
|
* @cra_refcnt: internally used
|
|
|
|
* @cra_destroy: internally used
|
|
|
|
*
|
2018-11-29 22:42:24 +08:00
|
|
|
* @stats: union of all possible crypto_istat_xxx structures
|
2018-12-13 16:36:38 +08:00
|
|
|
* @stats.aead: statistics for AEAD algorithm
|
|
|
|
* @stats.akcipher: statistics for akcipher algorithm
|
|
|
|
* @stats.cipher: statistics for cipher algorithm
|
|
|
|
* @stats.compress: statistics for compress algorithm
|
|
|
|
* @stats.hash: statistics for hash algorithm
|
|
|
|
* @stats.rng: statistics for rng algorithm
|
|
|
|
* @stats.kpp: statistics for KPP algorithm
|
2018-09-19 18:10:54 +08:00
|
|
|
*
|
2014-11-12 12:27:49 +08:00
|
|
|
* The struct crypto_alg describes a generic Crypto API algorithm and is common
|
|
|
|
* for all of the transformations. Any variable not documented here shall not
|
|
|
|
* be used by a cipher implementation as it is internal to the Crypto API.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
struct crypto_alg {
|
|
|
|
struct list_head cra_list;
|
2006-09-21 09:39:29 +08:00
|
|
|
struct list_head cra_users;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 cra_flags;
|
|
|
|
unsigned int cra_blocksize;
|
|
|
|
unsigned int cra_ctxsize;
|
2005-07-07 04:52:09 +08:00
|
|
|
unsigned int cra_alignmask;
|
2005-11-05 13:58:14 +08:00
|
|
|
|
|
|
|
int cra_priority;
|
2017-12-30 00:00:46 +08:00
|
|
|
refcount_t cra_refcnt;
|
2005-11-05 13:58:14 +08:00
|
|
|
|
2006-05-21 06:45:26 +08:00
|
|
|
char cra_name[CRYPTO_MAX_ALG_NAME];
|
|
|
|
char cra_driver_name[CRYPTO_MAX_ALG_NAME];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-21 22:06:54 +08:00
|
|
|
const struct crypto_type *cra_type;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
union {
|
|
|
|
struct cipher_alg cipher;
|
|
|
|
struct compress_alg compress;
|
|
|
|
} cra_u;
|
2006-05-24 11:02:26 +08:00
|
|
|
|
|
|
|
int (*cra_init)(struct crypto_tfm *tfm);
|
|
|
|
void (*cra_exit)(struct crypto_tfm *tfm);
|
2006-08-06 18:28:44 +08:00
|
|
|
void (*cra_destroy)(struct crypto_alg *alg);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct module *cra_module;
|
2018-09-19 18:10:54 +08:00
|
|
|
|
2018-11-29 22:42:16 +08:00
|
|
|
#ifdef CONFIG_CRYPTO_STATS
|
2018-09-19 18:10:54 +08:00
|
|
|
union {
|
2018-11-29 22:42:24 +08:00
|
|
|
struct crypto_istat_aead aead;
|
|
|
|
struct crypto_istat_akcipher akcipher;
|
|
|
|
struct crypto_istat_cipher cipher;
|
|
|
|
struct crypto_istat_compress compress;
|
|
|
|
struct crypto_istat_hash hash;
|
|
|
|
struct crypto_istat_rng rng;
|
|
|
|
struct crypto_istat_kpp kpp;
|
|
|
|
} stats;
|
2018-11-29 22:42:16 +08:00
|
|
|
#endif /* CONFIG_CRYPTO_STATS */
|
2018-09-19 18:10:54 +08:00
|
|
|
|
2015-06-18 14:00:48 +08:00
|
|
|
} CRYPTO_MINALIGN_ATTR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-11-29 22:42:21 +08:00
|
|
|
#ifdef CONFIG_CRYPTO_STATS
|
2018-11-29 22:42:26 +08:00
|
|
|
void crypto_stats_init(struct crypto_alg *alg);
|
2018-11-29 22:42:21 +08:00
|
|
|
void crypto_stats_get(struct crypto_alg *alg);
|
|
|
|
void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret);
|
|
|
|
void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret);
|
|
|
|
void crypto_stats_ahash_update(unsigned int nbytes, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_ahash_final(unsigned int nbytes, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret);
|
|
|
|
void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret);
|
|
|
|
void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret);
|
|
|
|
void crypto_stats_rng_seed(struct crypto_alg *alg, int ret);
|
|
|
|
void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, int ret);
|
|
|
|
void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg);
|
|
|
|
void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg);
|
|
|
|
#else
|
2018-11-29 22:42:26 +08:00
|
|
|
static inline void crypto_stats_init(struct crypto_alg *alg)
|
|
|
|
{}
|
2018-11-29 22:42:21 +08:00
|
|
|
static inline void crypto_stats_get(struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_ahash_update(unsigned int nbytes, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_ahash_final(unsigned int nbytes, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_rng_seed(struct crypto_alg *alg, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, int ret)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
static inline void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg)
|
|
|
|
{}
|
|
|
|
#endif
|
2017-10-18 15:00:38 +08:00
|
|
|
/*
|
|
|
|
* A helper struct for waiting for completion of async crypto ops
|
|
|
|
*/
|
|
|
|
struct crypto_wait {
|
|
|
|
struct completion completion;
|
|
|
|
int err;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro for declaring a crypto op async wait object on stack
|
|
|
|
*/
|
|
|
|
#define DECLARE_CRYPTO_WAIT(_wait) \
|
|
|
|
struct crypto_wait _wait = { \
|
|
|
|
COMPLETION_INITIALIZER_ONSTACK((_wait).completion), 0 }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Async ops completion helper functioons
|
|
|
|
*/
|
|
|
|
void crypto_req_done(struct crypto_async_request *req, int err);
|
|
|
|
|
|
|
|
static inline int crypto_wait_req(int err, struct crypto_wait *wait)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case -EINPROGRESS:
|
|
|
|
case -EBUSY:
|
|
|
|
wait_for_completion(&wait->completion);
|
|
|
|
reinit_completion(&wait->completion);
|
|
|
|
err = wait->err;
|
|
|
|
break;
|
2019-12-16 18:58:48 +08:00
|
|
|
}
|
2017-10-18 15:00:38 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void crypto_init_wait(struct crypto_wait *wait)
|
|
|
|
{
|
|
|
|
init_completion(&wait->completion);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Algorithm registration interface.
|
|
|
|
*/
|
|
|
|
int crypto_register_alg(struct crypto_alg *alg);
|
2019-12-16 07:51:19 +08:00
|
|
|
void crypto_unregister_alg(struct crypto_alg *alg);
|
2012-01-18 07:34:26 +08:00
|
|
|
int crypto_register_algs(struct crypto_alg *algs, int count);
|
2019-12-16 07:51:19 +08:00
|
|
|
void crypto_unregister_algs(struct crypto_alg *algs, int count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Algorithm query interface.
|
|
|
|
*/
|
2006-08-26 15:35:45 +08:00
|
|
|
int crypto_has_alg(const char *name, u32 type, u32 mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Transforms: user-instantiated objects which encapsulate algorithms
|
2006-07-30 09:53:01 +08:00
|
|
|
* and core processing logic. Managed via crypto_alloc_*() and
|
|
|
|
* crypto_free_*(), as well as the various helpers below.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct crypto_tfm {
|
|
|
|
|
|
|
|
u32 crt_flags;
|
2020-07-05 17:18:58 +08:00
|
|
|
|
|
|
|
int node;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-14 09:19:03 +08:00
|
|
|
void (*exit)(struct crypto_tfm *tfm);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct crypto_alg *__crt_alg;
|
2006-01-25 19:34:01 +08:00
|
|
|
|
2006-08-21 19:03:52 +08:00
|
|
|
void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2006-12-24 07:02:00 +08:00
|
|
|
struct crypto_comp {
|
|
|
|
struct crypto_tfm base;
|
|
|
|
};
|
|
|
|
|
2006-09-21 09:31:44 +08:00
|
|
|
enum {
|
|
|
|
CRYPTOA_UNSPEC,
|
|
|
|
CRYPTOA_ALG,
|
2007-01-01 15:37:02 +08:00
|
|
|
CRYPTOA_TYPE,
|
2007-08-29 19:27:26 +08:00
|
|
|
CRYPTOA_U32,
|
2007-01-01 15:37:02 +08:00
|
|
|
__CRYPTOA_MAX,
|
2006-09-21 09:31:44 +08:00
|
|
|
};
|
|
|
|
|
2007-01-01 15:37:02 +08:00
|
|
|
#define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
|
|
|
|
|
2007-08-29 19:27:26 +08:00
|
|
|
/* Maximum number of (rtattr) parameters for each template. */
|
|
|
|
#define CRYPTO_MAX_ATTRS 32
|
|
|
|
|
2006-09-21 09:31:44 +08:00
|
|
|
struct crypto_attr_alg {
|
|
|
|
char name[CRYPTO_MAX_ALG_NAME];
|
|
|
|
};
|
|
|
|
|
2007-01-01 15:37:02 +08:00
|
|
|
struct crypto_attr_type {
|
|
|
|
u32 type;
|
|
|
|
u32 mask;
|
|
|
|
};
|
|
|
|
|
2007-08-29 19:27:26 +08:00
|
|
|
struct crypto_attr_u32 {
|
|
|
|
u32 num;
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Transform user interface.
|
|
|
|
*/
|
|
|
|
|
2006-07-30 09:53:01 +08:00
|
|
|
struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
|
2009-02-05 13:48:24 +08:00
|
|
|
void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm);
|
|
|
|
|
|
|
|
static inline void crypto_free_tfm(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return crypto_destroy_tfm(tfm, tfm);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-31 17:08:25 +08:00
|
|
|
int alg_test(const char *driver, const char *alg, u32 type, u32 mask);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Transform helpers which query the underlying algorithm.
|
|
|
|
*/
|
|
|
|
static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->__crt_alg->cra_name;
|
|
|
|
}
|
|
|
|
|
2006-07-09 07:02:24 +08:00
|
|
|
static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->__crt_alg->cra_driver_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->__crt_alg->cra_priority;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->__crt_alg->cra_blocksize;
|
|
|
|
}
|
|
|
|
|
2005-07-07 04:53:29 +08:00
|
|
|
static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->__crt_alg->cra_alignmask;
|
|
|
|
}
|
|
|
|
|
2006-08-13 18:58:18 +08:00
|
|
|
static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return tfm->crt_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
|
|
|
|
{
|
|
|
|
tfm->crt_flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
|
|
|
|
{
|
|
|
|
tfm->crt_flags &= ~flags;
|
|
|
|
}
|
|
|
|
|
2005-07-07 04:51:52 +08:00
|
|
|
static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
|
|
|
|
{
|
2006-01-25 19:34:01 +08:00
|
|
|
return tfm->__crt_ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int crypto_tfm_ctx_alignment(void)
|
|
|
|
{
|
|
|
|
struct crypto_tfm *tfm;
|
|
|
|
return __alignof__(tfm->__crt_ctx);
|
2005-07-07 04:51:52 +08:00
|
|
|
}
|
|
|
|
|
2006-08-26 15:35:45 +08:00
|
|
|
static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
|
|
|
|
{
|
|
|
|
return (struct crypto_comp *)tfm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
|
|
|
|
u32 type, u32 mask)
|
|
|
|
{
|
|
|
|
type &= ~CRYPTO_ALG_TYPE_MASK;
|
|
|
|
type |= CRYPTO_ALG_TYPE_COMPRESS;
|
|
|
|
mask |= CRYPTO_ALG_TYPE_MASK;
|
|
|
|
|
|
|
|
return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm)
|
|
|
|
{
|
2006-12-24 07:02:00 +08:00
|
|
|
return &tfm->base;
|
2006-08-26 15:35:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void crypto_free_comp(struct crypto_comp *tfm)
|
|
|
|
{
|
|
|
|
crypto_free_tfm(crypto_comp_tfm(tfm));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask)
|
|
|
|
{
|
|
|
|
type &= ~CRYPTO_ALG_TYPE_MASK;
|
|
|
|
type |= CRYPTO_ALG_TYPE_COMPRESS;
|
|
|
|
mask |= CRYPTO_ALG_TYPE_MASK;
|
|
|
|
|
|
|
|
return crypto_has_alg(alg_name, type, mask);
|
|
|
|
}
|
|
|
|
|
2006-08-26 16:12:40 +08:00
|
|
|
static inline const char *crypto_comp_name(struct crypto_comp *tfm)
|
|
|
|
{
|
|
|
|
return crypto_tfm_alg_name(crypto_comp_tfm(tfm));
|
|
|
|
}
|
|
|
|
|
2019-12-03 05:42:29 +08:00
|
|
|
int crypto_comp_compress(struct crypto_comp *tfm,
|
|
|
|
const u8 *src, unsigned int slen,
|
|
|
|
u8 *dst, unsigned int *dlen);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-12-03 05:42:29 +08:00
|
|
|
int crypto_comp_decompress(struct crypto_comp *tfm,
|
|
|
|
const u8 *src, unsigned int slen,
|
|
|
|
u8 *dst, unsigned int *dlen);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* _LINUX_CRYPTO_H */
|
|
|
|
|