0001
0002
0003
0004
0005
0006 #ifndef _CRYPTO_AES_H
0007 #define _CRYPTO_AES_H
0008
0009 #include <linux/types.h>
0010 #include <linux/crypto.h>
0011
0012 #define AES_MIN_KEY_SIZE 16
0013 #define AES_MAX_KEY_SIZE 32
0014 #define AES_KEYSIZE_128 16
0015 #define AES_KEYSIZE_192 24
0016 #define AES_KEYSIZE_256 32
0017 #define AES_BLOCK_SIZE 16
0018 #define AES_MAX_KEYLENGTH (15 * 16)
0019 #define AES_MAX_KEYLENGTH_U32 (AES_MAX_KEYLENGTH / sizeof(u32))
0020
0021
0022
0023
0024
0025 struct crypto_aes_ctx {
0026 u32 key_enc[AES_MAX_KEYLENGTH_U32];
0027 u32 key_dec[AES_MAX_KEYLENGTH_U32];
0028 u32 key_length;
0029 };
0030
0031 extern const u32 crypto_ft_tab[4][256] ____cacheline_aligned;
0032 extern const u32 crypto_it_tab[4][256] ____cacheline_aligned;
0033
0034
0035
0036
0037 static inline int aes_check_keylen(unsigned int keylen)
0038 {
0039 switch (keylen) {
0040 case AES_KEYSIZE_128:
0041 case AES_KEYSIZE_192:
0042 case AES_KEYSIZE_256:
0043 break;
0044 default:
0045 return -EINVAL;
0046 }
0047
0048 return 0;
0049 }
0050
0051 int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
0052 unsigned int key_len);
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 int aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,
0069 unsigned int key_len);
0070
0071
0072
0073
0074
0075
0076
0077 void aes_encrypt(const struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
0078
0079
0080
0081
0082
0083
0084
0085 void aes_decrypt(const struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
0086
0087 extern const u8 crypto_aes_sbox[];
0088 extern const u8 crypto_aes_inv_sbox[];
0089
0090 #endif