/* SPDX-License-Identifier: GPL-2.0 */1/*2* Common values for AES algorithms3*/45#ifndef _CRYPTO_AES_H6#define _CRYPTO_AES_H78#include <linux/types.h>9#include <linux/crypto.h>1011#define AES_MIN_KEY_SIZE 1612#define AES_MAX_KEY_SIZE 3213#define AES_KEYSIZE_128 1614#define AES_KEYSIZE_192 2415#define AES_KEYSIZE_256 3216#define AES_BLOCK_SIZE 1617#define AES_MAX_KEYLENGTH (15 * 16)18#define AES_MAX_KEYLENGTH_U32 (AES_MAX_KEYLENGTH / sizeof(u32))1920/*21* Please ensure that the first two fields are 16-byte aligned22* relative to the start of the structure, i.e., don't move them!23*/24struct crypto_aes_ctx {25u32 key_enc[AES_MAX_KEYLENGTH_U32];26u32 key_dec[AES_MAX_KEYLENGTH_U32];27u32 key_length;28};2930extern const u32 crypto_ft_tab[4][256] ____cacheline_aligned;31extern const u32 crypto_it_tab[4][256] ____cacheline_aligned;3233/*34* validate key length for AES algorithms35*/36static inline int aes_check_keylen(unsigned int keylen)37{38switch (keylen) {39case AES_KEYSIZE_128:40case AES_KEYSIZE_192:41case AES_KEYSIZE_256:42break;43default:44return -EINVAL;45}4647return 0;48}4950int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,51unsigned int key_len);5253/**54* aes_expandkey - Expands the AES key as described in FIPS-19755* @ctx: The location where the computed key will be stored.56* @in_key: The supplied key.57* @key_len: The length of the supplied key.58*59* Returns 0 on success. The function fails only if an invalid key size (or60* pointer) is supplied.61* The expanded key size is 240 bytes (max of 14 rounds with a unique 16 bytes62* key schedule plus a 16 bytes key which is used before the first round).63* The decryption key is prepared for the "Equivalent Inverse Cipher" as64* described in FIPS-197. The first slot (16 bytes) of each key (enc or dec) is65* for the initial combination, the second slot for the first round and so on.66*/67int aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,68unsigned int key_len);6970/**71* aes_encrypt - Encrypt a single AES block72* @ctx: Context struct containing the key schedule73* @out: Buffer to store the ciphertext74* @in: Buffer containing the plaintext75*/76void aes_encrypt(const struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);7778/**79* aes_decrypt - Decrypt a single AES block80* @ctx: Context struct containing the key schedule81* @out: Buffer to store the plaintext82* @in: Buffer containing the ciphertext83*/84void aes_decrypt(const struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);8586extern const u8 crypto_aes_sbox[];87extern const u8 crypto_aes_inv_sbox[];8889void aescfb_encrypt(const struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src,90int len, const u8 iv[AES_BLOCK_SIZE]);91void aescfb_decrypt(const struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src,92int len, const u8 iv[AES_BLOCK_SIZE]);9394#endif959697