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)  * Glue Code for assembler optimized version of Blowfish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * CTR part based on code (crypto/ctr.c) by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <crypto/blowfish.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <crypto/internal/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* regular block cipher functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) asmlinkage void __blowfish_enc_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 				   bool xor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) asmlinkage void blowfish_dec_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* 4-way parallel cipher functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) asmlinkage void __blowfish_enc_blk_4way(struct bf_ctx *ctx, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 					const u8 *src, bool xor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) asmlinkage void blowfish_dec_blk_4way(struct bf_ctx *ctx, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 				      const u8 *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static inline void blowfish_enc_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	__blowfish_enc_blk(ctx, dst, src, false);
^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) static inline void blowfish_enc_blk_xor(struct bf_ctx *ctx, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 					const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	__blowfish_enc_blk(ctx, dst, src, true);
^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) static inline void blowfish_enc_blk_4way(struct bf_ctx *ctx, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 					 const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	__blowfish_enc_blk_4way(ctx, dst, src, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static inline void blowfish_enc_blk_xor_4way(struct bf_ctx *ctx, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				      const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	__blowfish_enc_blk_4way(ctx, dst, src, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void blowfish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	blowfish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static void blowfish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	blowfish_dec_blk(crypto_tfm_ctx(tfm), dst, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int blowfish_setkey_skcipher(struct crypto_skcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				    const u8 *key, unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return blowfish_setkey(&tfm->base, key, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int ecb_crypt(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		     void (*fn)(struct bf_ctx *, u8 *, const u8 *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		     void (*fn_4way)(struct bf_ctx *, u8 *, const u8 *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	unsigned int bsize = BF_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct bf_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	while ((nbytes = walk.nbytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		u8 *wsrc = walk.src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		u8 *wdst = walk.dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		/* Process four block batch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (nbytes >= bsize * 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				fn_4way(ctx, wdst, wsrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				wsrc += bsize * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				wdst += bsize * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				nbytes -= bsize * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			} while (nbytes >= bsize * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			if (nbytes < bsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		/* Handle leftovers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			fn(ctx, wdst, wsrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			wsrc += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			wdst += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			nbytes -= bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		} while (nbytes >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		err = skcipher_walk_done(&walk, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int ecb_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return ecb_crypt(req, blowfish_enc_blk, blowfish_enc_blk_4way);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int ecb_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return ecb_crypt(req, blowfish_dec_blk, blowfish_dec_blk_4way);
^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 unsigned int __cbc_encrypt(struct bf_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				  struct skcipher_walk *walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	unsigned int bsize = BF_BLOCK_SIZE;
^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) 	u64 *src = (u64 *)walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u64 *dst = (u64 *)walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	u64 *iv = (u64 *)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) 		*dst = *src ^ *iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		blowfish_enc_blk(ctx, (u8 *)dst, (u8 *)dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		iv = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		src += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		dst += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		nbytes -= bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	} while (nbytes >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	*(u64 *)walk->iv = *iv;
^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 cbc_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct bf_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	while ((nbytes = walk.nbytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		nbytes = __cbc_encrypt(ctx, &walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		err = skcipher_walk_done(&walk, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static unsigned int __cbc_decrypt(struct bf_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				  struct skcipher_walk *walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	unsigned int bsize = BF_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	u64 *src = (u64 *)walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	u64 *dst = (u64 *)walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	u64 ivs[4 - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	u64 last_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* Start of the last block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	src += nbytes / bsize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	dst += nbytes / bsize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	last_iv = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* Process four block batch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (nbytes >= bsize * 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			nbytes -= bsize * 4 - bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			src -= 4 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			dst -= 4 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			ivs[0] = src[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			ivs[1] = src[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			ivs[2] = src[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			blowfish_dec_blk_4way(ctx, (u8 *)dst, (u8 *)src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			dst[1] ^= ivs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			dst[2] ^= ivs[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			dst[3] ^= ivs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			nbytes -= bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			if (nbytes < bsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			*dst ^= *(src - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			src -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			dst -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		} while (nbytes >= bsize * 4);
^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) 	/* Handle leftovers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		blowfish_dec_blk(ctx, (u8 *)dst, (u8 *)src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		nbytes -= bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (nbytes < bsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		*dst ^= *(src - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		src -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		dst -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	*dst ^= *(u64 *)walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	*(u64 *)walk->iv = last_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return nbytes;
^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 int cbc_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct bf_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	while ((nbytes = walk.nbytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		nbytes = __cbc_decrypt(ctx, &walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		err = skcipher_walk_done(&walk, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static void ctr_crypt_final(struct bf_ctx *ctx, struct skcipher_walk *walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	u8 *ctrblk = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	u8 keystream[BF_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	u8 *dst = walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	blowfish_enc_blk(ctx, keystream, ctrblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	crypto_xor_cpy(dst, keystream, src, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	crypto_inc(ctrblk, BF_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static unsigned int __ctr_crypt(struct bf_ctx *ctx, struct skcipher_walk *walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	unsigned int bsize = BF_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	u64 *src = (u64 *)walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	u64 *dst = (u64 *)walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	u64 ctrblk = be64_to_cpu(*(__be64 *)walk->iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	__be64 ctrblocks[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/* Process four block batch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (nbytes >= bsize * 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			if (dst != src) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				dst[0] = src[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				dst[1] = src[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				dst[2] = src[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				dst[3] = src[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			/* create ctrblks for parallel encrypt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			ctrblocks[0] = cpu_to_be64(ctrblk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			ctrblocks[1] = cpu_to_be64(ctrblk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			ctrblocks[2] = cpu_to_be64(ctrblk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			ctrblocks[3] = cpu_to_be64(ctrblk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			blowfish_enc_blk_xor_4way(ctx, (u8 *)dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 						  (u8 *)ctrblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			src += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			dst += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		} while ((nbytes -= bsize * 4) >= bsize * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (nbytes < bsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* Handle leftovers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		if (dst != src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			*dst = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		ctrblocks[0] = cpu_to_be64(ctrblk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		blowfish_enc_blk_xor(ctx, (u8 *)dst, (u8 *)ctrblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		src += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		dst += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	} while ((nbytes -= bsize) >= bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	*(__be64 *)walk->iv = cpu_to_be64(ctrblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return nbytes;
^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 int ctr_crypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	struct bf_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	while ((nbytes = walk.nbytes) >= BF_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		nbytes = __ctr_crypt(ctx, &walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		err = skcipher_walk_done(&walk, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (nbytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		ctr_crypt_final(ctx, &walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		err = skcipher_walk_done(&walk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static struct crypto_alg bf_cipher_alg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	.cra_name		= "blowfish",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	.cra_driver_name	= "blowfish-asm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	.cra_priority		= 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	.cra_flags		= CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	.cra_blocksize		= BF_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	.cra_ctxsize		= sizeof(struct bf_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	.cra_alignmask		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	.cra_module		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	.cra_u = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		.cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			.cia_min_keysize	= BF_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			.cia_max_keysize	= BF_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			.cia_setkey		= blowfish_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			.cia_encrypt		= blowfish_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			.cia_decrypt		= blowfish_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static struct skcipher_alg bf_skcipher_algs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		.base.cra_name		= "ecb(blowfish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		.base.cra_driver_name	= "ecb-blowfish-asm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		.base.cra_priority	= 300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		.base.cra_blocksize	= BF_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		.base.cra_ctxsize	= sizeof(struct bf_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		.min_keysize		= BF_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		.max_keysize		= BF_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		.setkey			= blowfish_setkey_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		.encrypt		= ecb_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		.decrypt		= ecb_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		.base.cra_name		= "cbc(blowfish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		.base.cra_driver_name	= "cbc-blowfish-asm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		.base.cra_priority	= 300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		.base.cra_blocksize	= BF_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		.base.cra_ctxsize	= sizeof(struct bf_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		.min_keysize		= BF_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		.max_keysize		= BF_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		.ivsize			= BF_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		.setkey			= blowfish_setkey_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		.encrypt		= cbc_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		.decrypt		= cbc_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		.base.cra_name		= "ctr(blowfish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		.base.cra_driver_name	= "ctr-blowfish-asm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		.base.cra_priority	= 300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		.base.cra_blocksize	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		.base.cra_ctxsize	= sizeof(struct bf_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		.min_keysize		= BF_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		.max_keysize		= BF_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		.ivsize			= BF_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		.chunksize		= BF_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		.setkey			= blowfish_setkey_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		.encrypt		= ctr_crypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		.decrypt		= ctr_crypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static bool is_blacklisted_cpu(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (boot_cpu_data.x86 == 0x0f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		 * On Pentium 4, blowfish-x86_64 is slower than generic C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		 * implementation because use of 64bit rotates (which are really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		 * slow on P4). Therefore blacklist P4s.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static int force;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) module_param(force, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static int __init init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (!force && is_blacklisted_cpu()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			"blowfish-x86_64: performance on this CPU "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			"would be suboptimal: disabling "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			"blowfish-x86_64.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	err = crypto_register_alg(&bf_cipher_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	err = crypto_register_skciphers(bf_skcipher_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 					ARRAY_SIZE(bf_skcipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		crypto_unregister_alg(&bf_cipher_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static void __exit fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	crypto_unregister_alg(&bf_cipher_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	crypto_unregister_skciphers(bf_skcipher_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 				    ARRAY_SIZE(bf_skcipher_algs));
^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) module_init(init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) module_exit(fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) MODULE_DESCRIPTION("Blowfish Cipher Algorithm, asm optimized");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) MODULE_ALIAS_CRYPTO("blowfish");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) MODULE_ALIAS_CRYPTO("blowfish-asm");