^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Glue code for DES encryption optimized for sparc64 crypto opcodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2012 David S. Miller <davem@davemloft.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <crypto/internal/des.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <crypto/internal/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/fpumacro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/pstate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "opcodes.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct des_sparc64_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u64 encrypt_expkey[DES_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u64 decrypt_expkey[DES_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct des3_ede_sparc64_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u64 encrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u64 decrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void encrypt_to_decrypt(u64 *d, const u64 *e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) const u64 *s = e + (DES_EXPKEY_WORDS / 2) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) for (i = 0; i < DES_EXPKEY_WORDS / 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *d++ = *s--;
^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) extern void des_sparc64_key_expand(const u32 *input_key, u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int des_set_key(struct crypto_tfm *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* Even though we have special instructions for key expansion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * we call des_verify_key() so that we don't have to write our own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * weak key detection code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) err = crypto_des_verify_key(tfm, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return 0;
^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 des_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return des_set_key(crypto_skcipher_tfm(tfm), 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) extern void des_sparc64_crypt(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u64 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static void sparc_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const u64 *K = ctx->encrypt_expkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void sparc_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const u64 *K = ctx->decrypt_expkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern void des_sparc64_load_keys(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) extern void des_sparc64_ecb_crypt(const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static int __ecb_crypt(struct skcipher_request *req, bool encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) des_sparc64_ecb_crypt(walk.src.virt.addr, walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) round_down(nbytes, DES_BLOCK_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return 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) static int ecb_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return __ecb_crypt(req, true);
^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) static int ecb_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return __ecb_crypt(req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) extern void des_sparc64_cbc_encrypt(const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned int len, u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) extern void des_sparc64_cbc_decrypt(const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned int len, u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int __cbc_crypt(struct skcipher_request *req, bool encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) des_sparc64_cbc_encrypt(walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) round_down(nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) DES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) des_sparc64_cbc_decrypt(walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) round_down(nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) DES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return err;
^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) static int cbc_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return __cbc_crypt(req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int cbc_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return __cbc_crypt(req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u64 k1[DES_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u64 k2[DES_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) u64 k3[DES_EXPKEY_WORDS / 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) err = crypto_des3_ede_verify_key(tfm, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) des_sparc64_key_expand((const u32 *)key, k1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) key += DES_KEY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) des_sparc64_key_expand((const u32 *)key, k2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) key += DES_KEY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) des_sparc64_key_expand((const u32 *)key, k3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) memcpy(&dctx->encrypt_expkey[0], &k1[0], sizeof(k1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) encrypt_to_decrypt(&dctx->encrypt_expkey[DES_EXPKEY_WORDS / 2], &k2[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) memcpy(&dctx->encrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) &k3[0], sizeof(k3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) encrypt_to_decrypt(&dctx->decrypt_expkey[0], &k3[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) memcpy(&dctx->decrypt_expkey[DES_EXPKEY_WORDS / 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) &k2[0], sizeof(k2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) encrypt_to_decrypt(&dctx->decrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) &k1[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static int des3_ede_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return des3_ede_set_key(crypto_skcipher_tfm(tfm), key, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) u64 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static void sparc_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) const u64 *K = ctx->encrypt_expkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static void sparc_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) const u64 *K = ctx->decrypt_expkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) extern void des3_ede_sparc64_load_keys(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) extern void des3_ede_sparc64_ecb_crypt(const u64 *expkey, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int __ecb3_crypt(struct skcipher_request *req, bool encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) const u64 *K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) K = &ctx->encrypt_expkey[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) K = &ctx->decrypt_expkey[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) des3_ede_sparc64_load_keys(K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) des3_ede_sparc64_ecb_crypt(K, walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) round_down(nbytes, DES_BLOCK_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int ecb3_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return __ecb3_crypt(req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static int ecb3_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return __ecb3_crypt(req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) extern void des3_ede_sparc64_cbc_encrypt(const u64 *expkey, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) extern void des3_ede_sparc64_cbc_decrypt(const u64 *expkey, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int __cbc3_crypt(struct skcipher_request *req, bool encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) const u64 *K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) K = &ctx->encrypt_expkey[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) K = &ctx->decrypt_expkey[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) des3_ede_sparc64_load_keys(K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) des3_ede_sparc64_cbc_encrypt(K, walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) round_down(nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) DES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) des3_ede_sparc64_cbc_decrypt(K, walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) round_down(nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) DES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int cbc3_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return __cbc3_crypt(req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static int cbc3_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return __cbc3_crypt(req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static struct crypto_alg cipher_algs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .cra_name = "des",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .cra_driver_name = "des-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .cra_blocksize = DES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .cra_ctxsize = sizeof(struct des_sparc64_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .cra_u = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .cia_min_keysize = DES_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .cia_max_keysize = DES_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .cia_setkey = des_set_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .cia_encrypt = sparc_des_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .cia_decrypt = sparc_des_decrypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) .cra_name = "des3_ede",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .cra_driver_name = "des3_ede-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .cra_blocksize = DES3_EDE_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) .cra_u = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .cia_min_keysize = DES3_EDE_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .cia_max_keysize = DES3_EDE_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .cia_setkey = des3_ede_set_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .cia_encrypt = sparc_des3_ede_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .cia_decrypt = sparc_des3_ede_decrypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static struct skcipher_alg skcipher_algs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) .base.cra_name = "ecb(des)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .base.cra_driver_name = "ecb-des-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .base.cra_blocksize = DES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) .base.cra_ctxsize = sizeof(struct des_sparc64_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .min_keysize = DES_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .max_keysize = DES_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .setkey = des_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .encrypt = ecb_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .decrypt = ecb_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .base.cra_name = "cbc(des)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .base.cra_driver_name = "cbc-des-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .base.cra_blocksize = DES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .base.cra_ctxsize = sizeof(struct des_sparc64_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .min_keysize = DES_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .max_keysize = DES_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .ivsize = DES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .setkey = des_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .encrypt = cbc_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .decrypt = cbc_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) .base.cra_name = "ecb(des3_ede)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .base.cra_driver_name = "ecb-des3_ede-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .base.cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) .min_keysize = DES3_EDE_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .max_keysize = DES3_EDE_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) .setkey = des3_ede_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .encrypt = ecb3_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) .decrypt = ecb3_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) .base.cra_name = "cbc(des3_ede)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) .base.cra_driver_name = "cbc-des3_ede-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .base.cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .min_keysize = DES3_EDE_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .max_keysize = DES3_EDE_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .ivsize = DES3_EDE_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .setkey = des3_ede_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .encrypt = cbc3_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) .decrypt = cbc3_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^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) static bool __init sparc64_has_des_opcode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) unsigned long cfr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (!(cfr & CFR_DES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return true;
^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 int __init des_sparc64_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (!sparc64_has_des_opcode()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) pr_info("sparc64 des opcodes not available.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) pr_info("Using sparc64 des opcodes optimized DES implementation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) err = crypto_register_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) err = crypto_register_skciphers(skcipher_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ARRAY_SIZE(skcipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static void __exit des_sparc64_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) module_init(des_sparc64_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) module_exit(des_sparc64_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms, sparc64 des opcode accelerated");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) MODULE_ALIAS_CRYPTO("des");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) MODULE_ALIAS_CRYPTO("des3_ede");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) #include "crop_devid.c"