Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Symmetric key ciphers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #ifndef _CRYPTO_SKCIPHER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define _CRYPTO_SKCIPHER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *	struct skcipher_request - Symmetric key cipher request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	@cryptlen: Number of bytes to encrypt or decrypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *	@iv: Initialisation Vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *	@src: Source SG list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *	@dst: Destination SG list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *	@base: Underlying async request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *	@__ctx: Start of private context data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct skcipher_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	unsigned int cryptlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	u8 *iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct scatterlist *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct scatterlist *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct crypto_async_request base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	void *__ctx[] CRYPTO_MINALIGN_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) struct crypto_skcipher {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	unsigned int reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct crypto_tfm base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct crypto_sync_skcipher {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct crypto_skcipher base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * struct skcipher_alg - symmetric key cipher definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @min_keysize: Minimum key size supported by the transformation. This is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *		 smallest key length supported by this transformation algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *		 This must be set to one of the pre-defined values as this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *		 not hardware specific. Possible values for this field can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *		 found via git grep "_MIN_KEY_SIZE" include/crypto/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * @max_keysize: Maximum key size supported by the transformation. This is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *		 largest key length supported by this transformation algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *		 This must be set to one of the pre-defined values as this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *		 not hardware specific. Possible values for this field can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *		 found via git grep "_MAX_KEY_SIZE" include/crypto/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @setkey: Set key for the transformation. This function is used to either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *	    program a supplied key into the hardware or store the key in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *	    transformation context for programming it later. Note that this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *	    function does modify the transformation context. This function can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *	    be called multiple times during the existence of the transformation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *	    object, so one must make sure the key is properly reprogrammed into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *	    the hardware. This function is also responsible for checking the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *	    length for validity. In case a software fallback was put in place in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *	    the @cra_init call, this function might need to use the fallback if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *	    the algorithm doesn't support all of the key sizes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @encrypt: Encrypt a scatterlist of blocks. This function is used to encrypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *	     the supplied scatterlist containing the blocks of data. The crypto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *	     API consumer is responsible for aligning the entries of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *	     scatterlist properly and making sure the chunks are correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *	     sized. In case a software fallback was put in place in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *	     @cra_init call, this function might need to use the fallback if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *	     the algorithm doesn't support all of the key sizes. In case the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *	     key was stored in transformation context, the key might need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *	     re-programmed into the hardware in this function. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *	     shall not modify the transformation context, as this function may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *	     be called in parallel with the same transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * @decrypt: Decrypt a single block. This is a reverse counterpart to @encrypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *	     and the conditions are exactly the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @init: Initialize the cryptographic transformation object. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *	  is used to initialize the cryptographic transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *	  This function is called only once at the instantiation time, right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *	  after the transformation context was allocated. In case the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *	  cryptographic hardware has some special requirements which need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *	  be handled by software, this function shall check for the precise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *	  requirement of the transformation and put any software fallbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *	  in place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * @exit: Deinitialize the cryptographic transformation object. This is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *	  counterpart to @init, used to remove various changes set in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *	  @init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * @ivsize: IV size applicable for transformation. The consumer must provide an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *	    IV of exactly that size to perform the encrypt or decrypt operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * @chunksize: Equal to the block size except for stream ciphers such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *	       CTR where it is set to the underlying block size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * @walksize: Equal to the chunk size except in cases where the algorithm is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * 	      considerably more efficient if it can operate on multiple chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * 	      in parallel. Should be a multiple of chunksize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @base: Definition of a generic crypto algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * All fields except @ivsize are mandatory and must be filled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct skcipher_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int (*setkey)(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	              unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int (*encrypt)(struct skcipher_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int (*decrypt)(struct skcipher_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int (*init)(struct crypto_skcipher *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	void (*exit)(struct crypto_skcipher *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	unsigned int min_keysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	unsigned int max_keysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	unsigned int ivsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	unsigned int chunksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned int walksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct crypto_alg base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define MAX_SYNC_SKCIPHER_REQSIZE      384
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * This performs a type-check against the "tfm" argument to make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * all users have the correct skcipher tfm for doing on-stack requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define SYNC_SKCIPHER_REQUEST_ON_STACK(name, tfm) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	char __##name##_desc[sizeof(struct skcipher_request) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			     MAX_SYNC_SKCIPHER_REQSIZE + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			     (!(sizeof((struct crypto_sync_skcipher *)1 == \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				       (typeof(tfm))1))) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			    ] CRYPTO_MINALIGN_ATTR; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct skcipher_request *name = (void *)__##name##_desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * DOC: Symmetric Key Cipher API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * Symmetric key cipher API is used with the ciphers of type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * CRYPTO_ALG_TYPE_SKCIPHER (listed as type "skcipher" in /proc/crypto).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * Asynchronous cipher operations imply that the function invocation for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * cipher request returns immediately before the completion of the operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * The cipher request is scheduled as a separate kernel thread and therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * load-balanced on the different CPUs via the process scheduler. To allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * the kernel crypto API to inform the caller about the completion of a cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * request, the caller must provide a callback function. That function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * invoked with the cipher handle when the request completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * To support the asynchronous operation, additional information than just the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * cipher handle must be supplied to the kernel crypto API. That additional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * information is given by filling in the skcipher_request data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * For the symmetric key cipher API, the state is maintained with the tfm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * cipher handle. A single tfm can be used across multiple calls and in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * parallel. For asynchronous block cipher calls, context data supplied and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * only used by the caller can be referenced the request data structure in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * addition to the IV used for the cipher request. The maintenance of such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * state information would be important for a crypto driver implementer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * have, because when calling the callback function upon completion of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * cipher operation, that callback function may need some information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * which operation just finished if it invoked multiple in parallel. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * state information is unused by the kernel crypto API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static inline struct crypto_skcipher *__crypto_skcipher_cast(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return container_of(tfm, struct crypto_skcipher, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * crypto_alloc_skcipher() - allocate symmetric key cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  *	      skcipher cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * @type: specifies the type of the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * @mask: specifies the mask for the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * Allocate a cipher handle for an skcipher. The returned struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * crypto_skcipher is the cipher handle that is required for any subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * API invocation for that skcipher.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * Return: allocated cipher handle in case of success; IS_ERR() is true in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *	   of an error, PTR_ERR() returns the error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct crypto_skcipher *crypto_alloc_skcipher(const char *alg_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					      u32 type, u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct crypto_sync_skcipher *crypto_alloc_sync_skcipher(const char *alg_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 					      u32 type, u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static inline struct crypto_tfm *crypto_skcipher_tfm(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return &tfm->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * crypto_free_skcipher() - zeroize and free cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * @tfm: cipher handle to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * If @tfm is a NULL or error pointer, this function does nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline void crypto_free_skcipher(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	crypto_destroy_tfm(tfm, crypto_skcipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static inline void crypto_free_sync_skcipher(struct crypto_sync_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	crypto_free_skcipher(&tfm->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * crypto_has_skcipher() - Search for the availability of an skcipher.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  *	      skcipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * @type: specifies the type of the skcipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * @mask: specifies the mask for the skcipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * Return: true when the skcipher is known to the kernel crypto API; false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  *	   otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int crypto_has_skcipher(const char *alg_name, u32 type, u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static inline const char *crypto_skcipher_driver_name(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static inline struct skcipher_alg *crypto_skcipher_alg(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return container_of(crypto_skcipher_tfm(tfm)->__crt_alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			    struct skcipher_alg, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static inline unsigned int crypto_skcipher_alg_ivsize(struct skcipher_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return alg->ivsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * crypto_skcipher_ivsize() - obtain IV size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * The size of the IV for the skcipher referenced by the cipher handle is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * returned. This IV size may be zero if the cipher does not need an IV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * Return: IV size in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static inline unsigned int crypto_skcipher_ivsize(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return crypto_skcipher_alg(tfm)->ivsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static inline unsigned int crypto_sync_skcipher_ivsize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct crypto_sync_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return crypto_skcipher_ivsize(&tfm->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * crypto_skcipher_blocksize() - obtain block size of cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * The block size for the skcipher referenced with the cipher handle is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * returned. The caller may use that information to allocate appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * memory for the data returned by the encryption or decryption operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * Return: block size of cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline unsigned int crypto_skcipher_blocksize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return crypto_tfm_alg_blocksize(crypto_skcipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static inline unsigned int crypto_skcipher_alg_chunksize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct skcipher_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return alg->chunksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * crypto_skcipher_chunksize() - obtain chunk size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * The block size is set to one for ciphers such as CTR.  However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * you still need to provide incremental updates in multiples of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * the underlying block size as the IV does not have sub-block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * granularity.  This is known in this API as the chunk size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * Return: chunk size in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static inline unsigned int crypto_skcipher_chunksize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	return crypto_skcipher_alg_chunksize(crypto_skcipher_alg(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static inline unsigned int crypto_sync_skcipher_blocksize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct crypto_sync_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	return crypto_skcipher_blocksize(&tfm->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static inline unsigned int crypto_skcipher_alignmask(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return crypto_tfm_alg_alignmask(crypto_skcipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline u32 crypto_skcipher_get_flags(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return crypto_tfm_get_flags(crypto_skcipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static inline void crypto_skcipher_set_flags(struct crypto_skcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 					       u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	crypto_tfm_set_flags(crypto_skcipher_tfm(tfm), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static inline void crypto_skcipher_clear_flags(struct crypto_skcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 						 u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	crypto_tfm_clear_flags(crypto_skcipher_tfm(tfm), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static inline u32 crypto_sync_skcipher_get_flags(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct crypto_sync_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return crypto_skcipher_get_flags(&tfm->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static inline void crypto_sync_skcipher_set_flags(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct crypto_sync_skcipher *tfm, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	crypto_skcipher_set_flags(&tfm->base, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static inline void crypto_sync_skcipher_clear_flags(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct crypto_sync_skcipher *tfm, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	crypto_skcipher_clear_flags(&tfm->base, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * crypto_skcipher_setkey() - set key for cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * @key: buffer holding the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * @keylen: length of the key in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * The caller provided key is set for the skcipher referenced by the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * Note, the key length determines the cipher type. Many block ciphers implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * different cipher modes depending on the key size, such as AES-128 vs AES-192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * is performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * Return: 0 if the setting of the key was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int crypto_skcipher_setkey(struct crypto_skcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			   const u8 *key, unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static inline int crypto_sync_skcipher_setkey(struct crypto_sync_skcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 					 const u8 *key, unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return crypto_skcipher_setkey(&tfm->base, key, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static inline unsigned int crypto_skcipher_min_keysize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return crypto_skcipher_alg(tfm)->min_keysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static inline unsigned int crypto_skcipher_max_keysize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	return crypto_skcipher_alg(tfm)->max_keysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  * crypto_skcipher_reqtfm() - obtain cipher handle from request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * @req: skcipher_request out of which the cipher handle is to be obtained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * Return the crypto_skcipher handle when furnishing an skcipher_request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * Return: crypto_skcipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static inline struct crypto_skcipher *crypto_skcipher_reqtfm(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	return __crypto_skcipher_cast(req->base.tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	return container_of(tfm, struct crypto_sync_skcipher, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * crypto_skcipher_encrypt() - encrypt plaintext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * @req: reference to the skcipher_request handle that holds all information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  *	 needed to perform the cipher operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * Encrypt plaintext data using the skcipher_request handle. That data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * structure and how it is filled with data is discussed with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * skcipher_request_* functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) int crypto_skcipher_encrypt(struct skcipher_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  * crypto_skcipher_decrypt() - decrypt ciphertext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * @req: reference to the skcipher_request handle that holds all information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  *	 needed to perform the cipher operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * Decrypt ciphertext data using the skcipher_request handle. That data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * structure and how it is filled with data is discussed with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * skcipher_request_* functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) int crypto_skcipher_decrypt(struct skcipher_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * DOC: Symmetric Key Cipher Request Handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * The skcipher_request data structure contains all pointers to data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * required for the symmetric key cipher operation. This includes the cipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * handle (which can be used by multiple skcipher_request instances), pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * to plaintext and ciphertext, asynchronous callback function, etc. It acts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * as a handle to the skcipher_request_* API calls in a similar way as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * skcipher handle to the crypto_skcipher_* API calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * crypto_skcipher_reqsize() - obtain size of the request data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * @tfm: cipher handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * Return: number of bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static inline unsigned int crypto_skcipher_reqsize(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return tfm->reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  * skcipher_request_set_tfm() - update cipher handle reference in request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  * @req: request handle to be modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * @tfm: cipher handle that shall be added to the request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * Allow the caller to replace the existing skcipher handle in the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * data structure with a different one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static inline void skcipher_request_set_tfm(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 					    struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	req->base.tfm = crypto_skcipher_tfm(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static inline void skcipher_request_set_sync_tfm(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 					    struct crypto_sync_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	skcipher_request_set_tfm(req, &tfm->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static inline struct skcipher_request *skcipher_request_cast(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct crypto_async_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	return container_of(req, struct skcipher_request, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  * skcipher_request_alloc() - allocate request data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  * @tfm: cipher handle to be registered with the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  * @gfp: memory allocation flag that is handed to kmalloc by the API call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  * Allocate the request data structure that must be used with the skcipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  * encrypt and decrypt API calls. During the allocation, the provided skcipher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)  * handle is registered in the request data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  * Return: allocated request handle in case of success, or NULL if out of memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static inline struct skcipher_request *skcipher_request_alloc(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	struct crypto_skcipher *tfm, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	struct skcipher_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	req = kmalloc(sizeof(struct skcipher_request) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		      crypto_skcipher_reqsize(tfm), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	if (likely(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		skcipher_request_set_tfm(req, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  * skcipher_request_free() - zeroize and free request data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  * @req: request data structure cipher handle to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static inline void skcipher_request_free(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	kfree_sensitive(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static inline void skcipher_request_zero(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	memzero_explicit(req, sizeof(*req) + crypto_skcipher_reqsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)  * skcipher_request_set_callback() - set asynchronous callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)  * @req: request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)  * @flags: specify zero or an ORing of the flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  *	   CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  *	   increase the wait queue beyond the initial maximum size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  *	   CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * @compl: callback function pointer to be registered with the request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  * @data: The data pointer refers to memory that is not used by the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)  *	  crypto API, but provided to the callback function for it to use. Here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)  *	  the caller can provide a reference to memory the callback function can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)  *	  operate on. As the callback function is invoked asynchronously to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)  *	  related functionality, it may need to access data structures of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)  *	  related functionality which can be referenced using this pointer. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)  *	  callback function can access the memory via the "data" field in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)  *	  crypto_async_request data structure provided to the callback function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  * This function allows setting the callback function that is triggered once the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  * cipher operation completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)  * The callback function is registered with the skcipher_request handle and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * must comply with the following template::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  *	void callback_function(struct crypto_async_request *req, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static inline void skcipher_request_set_callback(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 						 u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 						 crypto_completion_t compl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 						 void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	req->base.complete = compl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	req->base.data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	req->base.flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)  * skcipher_request_set_crypt() - set data buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)  * @req: request handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)  * @src: source scatter / gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  * @dst: destination scatter / gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  * @cryptlen: number of bytes to process from @src
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  * @iv: IV for the cipher operation which must comply with the IV size defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  *      by crypto_skcipher_ivsize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  * This function allows setting of the source data and destination data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * scatter / gather lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)  * For encryption, the source is treated as the plaintext and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)  * destination is the ciphertext. For a decryption operation, the use is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)  * reversed - the source is the ciphertext and the destination is the plaintext.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static inline void skcipher_request_set_crypt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct scatterlist *src, struct scatterlist *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	unsigned int cryptlen, void *iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	req->src = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	req->dst = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	req->cryptlen = cryptlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	req->iv = iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #endif	/* _CRYPTO_SKCIPHER_H */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)