/* * Cryptographic API. * * AES Cipher Algorithm. * * Based on Brian Gladman's code. * * Linux developers: * Alexander Kjeldaas <[email protected]> * Herbert Valerio Riedel <[email protected]> * Kyle McMartin <[email protected]> * Adam J. Richter <[email protected]> (conversion to 2.5 API). * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * --------------------------------------------------------------------------- * Copyright (c) 2002, Dr Brian Gladman <[email protected]>, Worcester, UK. * All rights reserved. * * LICENSE TERMS * * The free distribution and use of this software in both source and binary * form is allowed (with or without changes) provided that: * * 1. distributions of this source code include the above copyright * notice, this list of conditions and the following disclaimer; * * 2. distributions in binary form include the above copyright * notice, this list of conditions and the following disclaimer * in the documentation and/or other associated materials; * * 3. the copyright holder's name is not used to endorse products * built using this software without specific written permission. * * ALTERNATIVELY, provided that this notice is retained in full, this product * may be distributed under the terms of the GNU General Public License (GPL), * in which case the provisions of the GPL apply INSTEAD OF those given above. * * DISCLAIMER * * This software is provided 'as is' with no explicit or implied warranties * in respect of its properties, including, but not limited to, correctness * and/or fitness for purpose. * --------------------------------------------------------------------------- */ #include <crypto/aes.h> #include <crypto/algapi.h> #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> #include <linux/errno.h> #include <asm/byteorder.h> #include <asm/unaligned.h> static inline u8 byte(const u32 x, const unsigned n) { … } /* cacheline-aligned to facilitate prefetching into cache */ __visible const u32 crypto_ft_tab[4][256] ____cacheline_aligned = …; static const u32 crypto_fl_tab[4][256] ____cacheline_aligned = …; __visible const u32 crypto_it_tab[4][256] ____cacheline_aligned = …; static const u32 crypto_il_tab[4][256] ____cacheline_aligned = …; EXPORT_SYMBOL_GPL(…); EXPORT_SYMBOL_GPL(…); /** * crypto_aes_set_key - Set the AES key. * @tfm: The %crypto_tfm that is used in the context. * @in_key: The input key. * @key_len: The size of the key. * * This function uses aes_expand_key() to expand the key. &crypto_aes_ctx * _must_ be the private data embedded in @tfm which is retrieved with * crypto_tfm_ctx(). * * Return: 0 on success; -EINVAL on failure (only happens for bad key lengths) */ int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len) { … } EXPORT_SYMBOL_GPL(…); /* encrypt a block of text */ #define f_rn(bo, bi, n, k) … #define f_nround(bo, bi, k) … #define f_rl(bo, bi, n, k) … #define f_lround(bo, bi, k) … static void crypto_aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { … } /* decrypt a block of text */ #define i_rn(bo, bi, n, k) … #define i_nround(bo, bi, k) … #define i_rl(bo, bi, n, k) … #define i_lround(bo, bi, k) … static void crypto_aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { … } static struct crypto_alg aes_alg = …; static int __init aes_init(void) { … } static void __exit aes_fini(void) { … } subsys_initcall(aes_init); module_exit(aes_fini); MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; MODULE_ALIAS_CRYPTO(…) …; MODULE_ALIAS_CRYPTO(…) …;