23 #include <linux/module.h>
25 #include <asm/byteorder.h>
27 #include <linux/types.h>
29 #define TEA_KEY_SIZE 16
30 #define TEA_BLOCK_SIZE 8
32 #define TEA_DELTA 0x9e3779b9
34 #define XTEA_KEY_SIZE 16
35 #define XTEA_BLOCK_SIZE 8
36 #define XTEA_ROUNDS 32
37 #define XTEA_DELTA 0x9e3779b9
47 static int tea_setkey(
struct crypto_tfm *tfm,
const u8 *in_key,
82 y += ((z << 4) + k0) ^ (z + sum) ^ ((z >> 5) + k1);
83 z += ((y << 4) + k2) ^ (y + sum) ^ ((y >> 5) + k3);
90 static void tea_decrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
94 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
111 z -= ((y << 4) + k2) ^ (y + sum) ^ ((y >> 5) + k3);
112 y -= ((z << 4) + k0) ^ (z + sum) ^ ((z >> 5) + k1);
120 static int xtea_setkey(
struct crypto_tfm *tfm,
const u8 *in_key,
123 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
135 static void xtea_encrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
139 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
146 while (sum != limit) {
147 y += ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->
KEY[sum&3]);
149 z += ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->
KEY[sum>>11 &3]);
156 static void xtea_decrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
159 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
169 z -= ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->
KEY[sum>>11 & 3]);
171 y -= ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->
KEY[sum & 3]);
179 static void xeta_encrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
183 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
190 while (sum != limit) {
191 y += (z << 4 ^ z >> 5) + (z ^ sum) + ctx->
KEY[sum&3];
193 z += (y << 4 ^ y >> 5) + (y ^ sum) + ctx->
KEY[sum>>11 &3];
200 static void xeta_decrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
203 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
213 z -= (y << 4 ^ y >> 5) + (y ^ sum) + ctx->
KEY[sum>>11 & 3];
215 y -= (z << 4 ^ z >> 5) + (z ^ sum) + ctx->
KEY[sum & 3];
226 .cra_ctxsize =
sizeof (
struct tea_ctx),
229 .cra_u = { .cipher = {
232 .cia_setkey = tea_setkey,
233 .cia_encrypt = tea_encrypt,
234 .cia_decrypt = tea_decrypt } }
239 .cra_ctxsize =
sizeof (
struct xtea_ctx),
242 .cra_u = { .cipher = {
245 .cia_setkey = xtea_setkey,
246 .cia_encrypt = xtea_encrypt,
247 .cia_decrypt = xtea_decrypt } }
252 .cra_ctxsize =
sizeof (
struct xtea_ctx),
255 .cra_u = { .cipher = {
258 .cia_setkey = xtea_setkey,
259 .cia_encrypt = xeta_encrypt,
260 .cia_decrypt = xeta_decrypt } }
263 static int __init tea_mod_init(
void)
268 static void __exit tea_mod_fini(
void)