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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * CFB: Cipher FeedBack mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2018 James.Bottomley@HansenPartnership.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * CFB is a stream cipher mode which is layered on to a block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * encryption scheme.  It works very much like a one time pad where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * the pad is generated initially from the encrypted IV and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * subsequently from the encrypted previous block of ciphertext.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * pad is XOR'd into the plain text to get the final ciphertext.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * The scheme of CFB is best described by wikipedia:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#CFB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Note that since the pad for both encryption and decryption is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * generated by an encryption operation, CFB never uses the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * decryption function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <crypto/internal/cipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <crypto/internal/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned int crypto_cfb_bsize(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return crypto_cipher_blocksize(skcipher_cipher_simple(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static void crypto_cfb_encrypt_one(struct crypto_skcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 					  const u8 *src, u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	crypto_cipher_encrypt_one(skcipher_cipher_simple(tfm), dst, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* final encrypt and decrypt is the same */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static void crypto_cfb_final(struct skcipher_walk *walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			     struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	const unsigned long alignmask = crypto_skcipher_alignmask(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u8 *dst = walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u8 *iv = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	crypto_cfb_encrypt_one(tfm, iv, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	crypto_xor_cpy(dst, stream, src, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int crypto_cfb_encrypt_segment(struct skcipher_walk *walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				      struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	const unsigned int bsize = crypto_cfb_bsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u8 *dst = walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u8 *iv = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		crypto_cfb_encrypt_one(tfm, iv, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		crypto_xor(dst, src, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		iv = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		src += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		dst += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	} while ((nbytes -= bsize) >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	memcpy(walk->iv, iv, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int crypto_cfb_encrypt_inplace(struct skcipher_walk *walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 				      struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	const unsigned int bsize = crypto_cfb_bsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u8 *iv = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	u8 tmp[MAX_CIPHER_BLOCKSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		crypto_cfb_encrypt_one(tfm, iv, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		crypto_xor(src, tmp, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		iv = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		src += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	} while ((nbytes -= bsize) >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	memcpy(walk->iv, iv, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int crypto_cfb_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	unsigned int bsize = crypto_cfb_bsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	while (walk.nbytes >= bsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (walk.src.virt.addr == walk.dst.virt.addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			err = crypto_cfb_encrypt_inplace(&walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			err = crypto_cfb_encrypt_segment(&walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		err = skcipher_walk_done(&walk, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (walk.nbytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		crypto_cfb_final(&walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		err = skcipher_walk_done(&walk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int crypto_cfb_decrypt_segment(struct skcipher_walk *walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				      struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	const unsigned int bsize = crypto_cfb_bsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u8 *dst = walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	u8 *iv = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		crypto_cfb_encrypt_one(tfm, iv, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		crypto_xor(dst, src, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		iv = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		src += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		dst += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	} while ((nbytes -= bsize) >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	memcpy(walk->iv, iv, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				      struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	const unsigned int bsize = crypto_cfb_bsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	u8 * const iv = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	u8 tmp[MAX_CIPHER_BLOCKSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		crypto_cfb_encrypt_one(tfm, iv, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		memcpy(iv, src, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		crypto_xor(src, tmp, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		src += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	} while ((nbytes -= bsize) >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return nbytes;
^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) static int crypto_cfb_decrypt_blocks(struct skcipher_walk *walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				     struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (walk->src.virt.addr == walk->dst.virt.addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return crypto_cfb_decrypt_inplace(walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return crypto_cfb_decrypt_segment(walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int crypto_cfb_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	const unsigned int bsize = crypto_cfb_bsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	while (walk.nbytes >= bsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		err = crypto_cfb_decrypt_blocks(&walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		err = skcipher_walk_done(&walk, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (walk.nbytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		crypto_cfb_final(&walk, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		err = skcipher_walk_done(&walk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int crypto_cfb_create(struct crypto_template *tmpl, struct rtattr **tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct skcipher_instance *inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct crypto_alg *alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	inst = skcipher_alloc_instance_simple(tmpl, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (IS_ERR(inst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return PTR_ERR(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	alg = skcipher_ialg_simple(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	/* CFB mode is a stream cipher. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	inst->alg.base.cra_blocksize = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	 * To simplify the implementation, configure the skcipher walk to only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	 * give a partial block at the very end, never earlier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	inst->alg.chunksize = alg->cra_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	inst->alg.encrypt = crypto_cfb_encrypt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	inst->alg.decrypt = crypto_cfb_decrypt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	err = skcipher_register_instance(tmpl, inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		inst->free(inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static struct crypto_template crypto_cfb_tmpl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	.name = "cfb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	.create = crypto_cfb_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	.module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int __init crypto_cfb_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return crypto_register_template(&crypto_cfb_tmpl);
^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) static void __exit crypto_cfb_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	crypto_unregister_template(&crypto_cfb_tmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) subsys_initcall(crypto_cfb_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) module_exit(crypto_cfb_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_DESCRIPTION("CFB block cipher mode of operation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) MODULE_ALIAS_CRYPTO("cfb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) MODULE_IMPORT_NS(CRYPTO_INTERNAL);