lib/crypto/powerpc/aes.h

Source file repositories/reference/linux-study-clean/lib/crypto/powerpc/aes.h

File Facts

System
Linux kernel
Corpus path
lib/crypto/powerpc/aes.h
Extension
.h
Size
7054 bytes
Lines
241
Domain
Kernel Services
Bucket
lib
Inferred role
Kernel Services: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

if (inv_k) {
			ret = aes_p8_set_decrypt_key(in_key, keybits,
						     &inv_k->p8);
			/* ... and likewise for aes_p8_set_decrypt_key(). */
			WARN_ON_ONCE(ret);
		}
		disable_kernel_vsx();
		pagefault_enable();
		preempt_enable();
	} else {
		aes_expandkey_generic(k->rndkeys,
				      inv_k ? inv_k->inv_rndkeys : NULL,
				      in_key, key_len);
		/* Mark the key as using the generic format. */
		k->p8.nrounds = 0;
		if (inv_k)
			inv_k->p8.nrounds = 0;
	}
}

static void aes_encrypt_arch(const struct aes_enckey *key,
			     u8 out[AES_BLOCK_SIZE],
			     const u8 in[AES_BLOCK_SIZE])
{
	if (static_branch_likely(&have_vec_crypto) &&
	    likely(is_vsx_format(&key->k.p8) && may_use_simd())) {
		preempt_disable();
		pagefault_disable();
		enable_kernel_vsx();
		aes_p8_encrypt(in, out, &key->k.p8);
		disable_kernel_vsx();
		pagefault_enable();
		preempt_enable();
	} else if (unlikely(is_vsx_format(&key->k.p8))) {
		/*
		 * This handles (the hopefully extremely rare) case where a key
		 * was prepared using the VSX optimized format, then encryption
		 * is done in a context that cannot use VSX instructions.
		 */
		u32 rndkeys[AES_MAX_KEYLENGTH_U32];

		for (int i = 0; i < 4 * (key->nrounds + 1); i += 4)
			rndkey_from_vsx(&rndkeys[i],
					&key->k.p8.rndkeys[i], false);
		aes_encrypt_generic(rndkeys, key->nrounds, out, in);
	} else {
		aes_encrypt_generic(key->k.rndkeys, key->nrounds, out, in);
	}
}

static void aes_decrypt_arch(const struct aes_key *key, u8 out[AES_BLOCK_SIZE],
			     const u8 in[AES_BLOCK_SIZE])
{
	if (static_branch_likely(&have_vec_crypto) &&
	    likely(is_vsx_format(&key->inv_k.p8) && may_use_simd())) {
		preempt_disable();
		pagefault_disable();
		enable_kernel_vsx();
		aes_p8_decrypt(in, out, &key->inv_k.p8);
		disable_kernel_vsx();
		pagefault_enable();
		preempt_enable();
	} else if (unlikely(is_vsx_format(&key->inv_k.p8))) {
		/*
		 * This handles (the hopefully extremely rare) case where a key
		 * was prepared using the VSX optimized format, then decryption
		 * is done in a context that cannot use VSX instructions.
		 */
		u32 inv_rndkeys[AES_MAX_KEYLENGTH_U32];
		int i;

		rndkey_from_vsx(&inv_rndkeys[0],
				&key->inv_k.p8.rndkeys[0], false);
		for (i = 4; i < 4 * key->nrounds; i += 4) {
			rndkey_from_vsx(&inv_rndkeys[i],
					&key->inv_k.p8.rndkeys[i], true);
		}
		rndkey_from_vsx(&inv_rndkeys[i],
				&key->inv_k.p8.rndkeys[i], false);
		aes_decrypt_generic(inv_rndkeys, key->nrounds, out, in);
	} else {
		aes_decrypt_generic(key->inv_k.inv_rndkeys, key->nrounds,
				    out, in);
	}
}

#define aes_mod_init_arch aes_mod_init_arch
static void aes_mod_init_arch(void)
{
	if (cpu_has_feature(CPU_FTR_ARCH_207S) &&

Annotation

Implementation Notes