^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 AES 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) * This is based largely upon arch/x86/crypto/aesni-intel_glue.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2008, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Huang Ying <ying.huang@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Added RFC4106 AES-GCM support for 128-bit keys under the AEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * interface for 64-bit kernels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Authors: Adrian Hoban <adrian.hoban@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Gabriele Paoloni <gabriele.paoloni@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Tadeusz Struk (tadeusz.struk@intel.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Aidan O'Mahony (aidan.o.mahony@intel.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Copyright (c) 2010, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <crypto/aes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <crypto/internal/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/fpumacro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/pstate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "opcodes.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct aes_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) void (*encrypt)(const u64 *key, const u32 *input, u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void (*decrypt)(const u64 *key, const u32 *input, u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void (*load_encrypt_keys)(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void (*load_decrypt_keys)(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void (*ecb_encrypt)(const u64 *key, const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) void (*ecb_decrypt)(const u64 *key, const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void (*cbc_encrypt)(const u64 *key, const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned int len, u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) void (*cbc_decrypt)(const u64 *key, const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int len, u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void (*ctr_crypt)(const u64 *key, const u64 *input, u64 *output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int len, u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct crypto_sparc64_aes_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct aes_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u64 key[AES_MAX_KEYLENGTH / sizeof(u64)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u32 key_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u32 expanded_key_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) extern void aes_sparc64_encrypt_128(const u64 *key, const u32 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) extern void aes_sparc64_encrypt_192(const u64 *key, const u32 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) extern void aes_sparc64_encrypt_256(const u64 *key, const u32 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) extern void aes_sparc64_decrypt_128(const u64 *key, const u32 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) extern void aes_sparc64_decrypt_192(const u64 *key, const u32 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) extern void aes_sparc64_decrypt_256(const u64 *key, const u32 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u32 *output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) extern void aes_sparc64_load_encrypt_keys_128(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) extern void aes_sparc64_load_encrypt_keys_192(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) extern void aes_sparc64_load_encrypt_keys_256(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) extern void aes_sparc64_load_decrypt_keys_128(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) extern void aes_sparc64_load_decrypt_keys_192(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) extern void aes_sparc64_load_decrypt_keys_256(const u64 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) extern void aes_sparc64_ecb_encrypt_128(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) extern void aes_sparc64_ecb_encrypt_192(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) extern void aes_sparc64_ecb_encrypt_256(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) extern void aes_sparc64_ecb_decrypt_128(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern void aes_sparc64_ecb_decrypt_192(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) extern void aes_sparc64_ecb_decrypt_256(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) u64 *output, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) extern void aes_sparc64_cbc_encrypt_128(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) extern void aes_sparc64_cbc_encrypt_192(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) extern void aes_sparc64_cbc_encrypt_256(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern void aes_sparc64_cbc_decrypt_128(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) extern void aes_sparc64_cbc_decrypt_192(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) extern void aes_sparc64_cbc_decrypt_256(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) extern void aes_sparc64_ctr_crypt_128(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) extern void aes_sparc64_ctr_crypt_192(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) extern void aes_sparc64_ctr_crypt_256(const u64 *key, const u64 *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u64 *output, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u64 *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static struct aes_ops aes128_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .encrypt = aes_sparc64_encrypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .decrypt = aes_sparc64_decrypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .load_encrypt_keys = aes_sparc64_load_encrypt_keys_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .load_decrypt_keys = aes_sparc64_load_decrypt_keys_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .ecb_encrypt = aes_sparc64_ecb_encrypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .ecb_decrypt = aes_sparc64_ecb_decrypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .cbc_encrypt = aes_sparc64_cbc_encrypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .cbc_decrypt = aes_sparc64_cbc_decrypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .ctr_crypt = aes_sparc64_ctr_crypt_128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static struct aes_ops aes192_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .encrypt = aes_sparc64_encrypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .decrypt = aes_sparc64_decrypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .load_encrypt_keys = aes_sparc64_load_encrypt_keys_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .load_decrypt_keys = aes_sparc64_load_decrypt_keys_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .ecb_encrypt = aes_sparc64_ecb_encrypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .ecb_decrypt = aes_sparc64_ecb_decrypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .cbc_encrypt = aes_sparc64_cbc_encrypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .cbc_decrypt = aes_sparc64_cbc_decrypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .ctr_crypt = aes_sparc64_ctr_crypt_192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static struct aes_ops aes256_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .encrypt = aes_sparc64_encrypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .decrypt = aes_sparc64_decrypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .load_encrypt_keys = aes_sparc64_load_encrypt_keys_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .load_decrypt_keys = aes_sparc64_load_decrypt_keys_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .ecb_encrypt = aes_sparc64_ecb_encrypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .ecb_decrypt = aes_sparc64_ecb_decrypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .cbc_encrypt = aes_sparc64_cbc_encrypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .cbc_decrypt = aes_sparc64_cbc_decrypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .ctr_crypt = aes_sparc64_ctr_crypt_256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) extern void aes_sparc64_key_expand(const u32 *in_key, u64 *output_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned int key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) unsigned int key_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct crypto_sparc64_aes_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) switch (key_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) case AES_KEYSIZE_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ctx->expanded_key_length = 0xb0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ctx->ops = &aes128_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) case AES_KEYSIZE_192:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ctx->expanded_key_length = 0xd0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ctx->ops = &aes192_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) case AES_KEYSIZE_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ctx->expanded_key_length = 0xf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ctx->ops = &aes256_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return -EINVAL;
^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) aes_sparc64_key_expand((const u32 *)in_key, &ctx->key[0], key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ctx->key_length = key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int aes_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *in_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) unsigned int key_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return aes_set_key(crypto_skcipher_tfm(tfm), in_key, key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void crypto_aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct crypto_sparc64_aes_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ctx->ops->encrypt(&ctx->key[0], (const u32 *) src, (u32 *) dst);
^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) static void crypto_aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct crypto_sparc64_aes_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ctx->ops->decrypt(&ctx->key[0], (const u32 *) src, (u32 *) dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int ecb_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) const struct crypto_sparc64_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (err)
^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) ctx->ops->load_encrypt_keys(&ctx->key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ctx->ops->ecb_encrypt(&ctx->key[0], walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) round_down(nbytes, AES_BLOCK_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) err = skcipher_walk_done(&walk, nbytes % AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return err;
^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) static int ecb_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) const struct crypto_sparc64_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) const u64 *key_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ctx->ops->load_decrypt_keys(&ctx->key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) key_end = &ctx->key[ctx->expanded_key_length / sizeof(u64)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ctx->ops->ecb_decrypt(key_end, walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) round_down(nbytes, AES_BLOCK_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) err = skcipher_walk_done(&walk, nbytes % AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int cbc_encrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) const struct crypto_sparc64_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ctx->ops->load_encrypt_keys(&ctx->key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ctx->ops->cbc_encrypt(&ctx->key[0], walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) round_down(nbytes, AES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) err = skcipher_walk_done(&walk, nbytes % AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static int cbc_decrypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) const struct crypto_sparc64_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) const u64 *key_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ctx->ops->load_decrypt_keys(&ctx->key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) key_end = &ctx->key[ctx->expanded_key_length / sizeof(u64)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) while ((nbytes = walk.nbytes) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ctx->ops->cbc_decrypt(key_end, walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) round_down(nbytes, AES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) err = skcipher_walk_done(&walk, nbytes % AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void ctr_crypt_final(const struct crypto_sparc64_aes_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct skcipher_walk *walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) u8 *ctrblk = walk->iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) u64 keystream[AES_BLOCK_SIZE / sizeof(u64)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) u8 *src = walk->src.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) u8 *dst = walk->dst.virt.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) unsigned int nbytes = walk->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ctx->ops->ecb_encrypt(&ctx->key[0], (const u64 *)ctrblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) keystream, AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) crypto_xor_cpy(dst, (u8 *) keystream, src, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) crypto_inc(ctrblk, AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int ctr_crypt(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) const struct crypto_sparc64_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) err = skcipher_walk_virt(&walk, req, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ctx->ops->load_encrypt_keys(&ctx->key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ctx->ops->ctr_crypt(&ctx->key[0], walk.src.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) round_down(nbytes, AES_BLOCK_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) walk.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) err = skcipher_walk_done(&walk, nbytes % AES_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (walk.nbytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ctr_crypt_final(ctx, &walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) err = skcipher_walk_done(&walk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) fprs_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static struct crypto_alg cipher_alg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .cra_name = "aes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .cra_driver_name = "aes-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) .cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .cra_blocksize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .cra_ctxsize = sizeof(struct crypto_sparc64_aes_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .cra_alignmask = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .cra_u = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) .cia_min_keysize = AES_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .cia_max_keysize = AES_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) .cia_setkey = aes_set_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .cia_encrypt = crypto_aes_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) .cia_decrypt = crypto_aes_decrypt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static struct skcipher_alg skcipher_algs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .base.cra_name = "ecb(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .base.cra_driver_name = "ecb-aes-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .base.cra_blocksize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .base.cra_ctxsize = sizeof(struct crypto_sparc64_aes_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .min_keysize = AES_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .max_keysize = AES_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .setkey = aes_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .encrypt = ecb_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .decrypt = ecb_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .base.cra_name = "cbc(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .base.cra_driver_name = "cbc-aes-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .base.cra_blocksize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .base.cra_ctxsize = sizeof(struct crypto_sparc64_aes_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .min_keysize = AES_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) .max_keysize = AES_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) .ivsize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .setkey = aes_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) .encrypt = cbc_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .decrypt = cbc_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .base.cra_name = "ctr(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .base.cra_driver_name = "ctr-aes-sparc64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .base.cra_blocksize = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) .base.cra_ctxsize = sizeof(struct crypto_sparc64_aes_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .base.cra_alignmask = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) .min_keysize = AES_MIN_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) .max_keysize = AES_MAX_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) .ivsize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) .setkey = aes_set_key_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .encrypt = ctr_crypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .decrypt = ctr_crypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .chunksize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static bool __init sparc64_has_aes_opcode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) unsigned long cfr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (!(cfr & CFR_AES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static int __init aes_sparc64_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (!sparc64_has_aes_opcode()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) pr_info("sparc64 aes opcodes not available.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) pr_info("Using sparc64 aes opcodes optimized AES implementation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) err = crypto_register_alg(&cipher_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) err = crypto_register_skciphers(skcipher_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) ARRAY_SIZE(skcipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) crypto_unregister_alg(&cipher_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static void __exit aes_sparc64_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) crypto_unregister_alg(&cipher_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) module_init(aes_sparc64_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) module_exit(aes_sparc64_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, sparc64 aes opcode accelerated");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) MODULE_ALIAS_CRYPTO("aes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #include "crop_devid.c"