^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Cryptographic API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * TEA, XTEA, and XETA crypto alogrithms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * The TEA and Xtended TEA algorithms were developed by David Wheeler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * and Roger Needham at the Computer Laboratory of Cambridge University.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Due to the order of evaluation in XTEA many people have incorrectly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * implemented it. XETA (XTEA in the wrong order), exists for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * compatibility with these implementations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright (c) 2004 Aaron Grothe ajgrothe@yahoo.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define TEA_KEY_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define TEA_BLOCK_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define TEA_ROUNDS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define TEA_DELTA 0x9e3779b9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define XTEA_KEY_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define XTEA_BLOCK_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define XTEA_ROUNDS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define XTEA_DELTA 0x9e3779b9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct tea_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 KEY[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct xtea_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u32 KEY[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned int key_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) const __le32 *key = (const __le32 *)in_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ctx->KEY[0] = le32_to_cpu(key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ctx->KEY[1] = le32_to_cpu(key[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ctx->KEY[2] = le32_to_cpu(key[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ctx->KEY[3] = le32_to_cpu(key[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static void tea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u32 y, z, n, sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u32 k0, k1, k2, k3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) const __le32 *in = (const __le32 *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) __le32 *out = (__le32 *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) y = le32_to_cpu(in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) z = le32_to_cpu(in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) k0 = ctx->KEY[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) k1 = ctx->KEY[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) k2 = ctx->KEY[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) k3 = ctx->KEY[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) n = TEA_ROUNDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) while (n-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) sum += TEA_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) y += ((z << 4) + k0) ^ (z + sum) ^ ((z >> 5) + k1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) z += ((y << 4) + k2) ^ (y + sum) ^ ((y >> 5) + k3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) out[0] = cpu_to_le32(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) out[1] = cpu_to_le32(z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 y, z, n, sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 k0, k1, k2, k3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) const __le32 *in = (const __le32 *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) __le32 *out = (__le32 *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) y = le32_to_cpu(in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) z = le32_to_cpu(in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) k0 = ctx->KEY[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) k1 = ctx->KEY[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) k2 = ctx->KEY[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) k3 = ctx->KEY[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sum = TEA_DELTA << 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) n = TEA_ROUNDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) while (n-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) z -= ((y << 4) + k2) ^ (y + sum) ^ ((y >> 5) + k3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) y -= ((z << 4) + k0) ^ (z + sum) ^ ((z >> 5) + k1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sum -= TEA_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) out[0] = cpu_to_le32(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) out[1] = cpu_to_le32(z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned int key_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) const __le32 *key = (const __le32 *)in_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ctx->KEY[0] = le32_to_cpu(key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ctx->KEY[1] = le32_to_cpu(key[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ctx->KEY[2] = le32_to_cpu(key[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ctx->KEY[3] = le32_to_cpu(key[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void xtea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u32 y, z, sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u32 limit = XTEA_DELTA * XTEA_ROUNDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) const __le32 *in = (const __le32 *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) __le32 *out = (__le32 *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) y = le32_to_cpu(in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) z = le32_to_cpu(in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) while (sum != limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) y += ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->KEY[sum&3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) sum += XTEA_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) z += ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->KEY[sum>>11 &3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) out[0] = cpu_to_le32(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) out[1] = cpu_to_le32(z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static void xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) u32 y, z, sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) const __le32 *in = (const __le32 *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) __le32 *out = (__le32 *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) y = le32_to_cpu(in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) z = le32_to_cpu(in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) sum = XTEA_DELTA * XTEA_ROUNDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) while (sum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) z -= ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->KEY[sum>>11 & 3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) sum -= XTEA_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) y -= ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->KEY[sum & 3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) out[0] = cpu_to_le32(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) out[1] = cpu_to_le32(z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static void xeta_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u32 y, z, sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) u32 limit = XTEA_DELTA * XTEA_ROUNDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) const __le32 *in = (const __le32 *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) __le32 *out = (__le32 *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) y = le32_to_cpu(in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) z = le32_to_cpu(in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) while (sum != limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) y += (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum&3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) sum += XTEA_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) z += (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 &3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) out[0] = cpu_to_le32(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) out[1] = cpu_to_le32(z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) u32 y, z, sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) const __le32 *in = (const __le32 *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) __le32 *out = (__le32 *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) y = le32_to_cpu(in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) z = le32_to_cpu(in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) sum = XTEA_DELTA * XTEA_ROUNDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) while (sum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) z -= (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 & 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) sum -= XTEA_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) y -= (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum & 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) out[0] = cpu_to_le32(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) out[1] = cpu_to_le32(z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static struct crypto_alg tea_algs[3] = { {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .cra_name = "tea",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .cra_driver_name = "tea-generic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .cra_blocksize = TEA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .cra_ctxsize = sizeof (struct tea_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .cra_alignmask = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .cra_u = { .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .cia_min_keysize = TEA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .cia_max_keysize = TEA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .cia_setkey = tea_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .cia_encrypt = tea_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .cia_decrypt = tea_decrypt } }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .cra_name = "xtea",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .cra_driver_name = "xtea-generic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .cra_blocksize = XTEA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .cra_ctxsize = sizeof (struct xtea_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .cra_alignmask = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .cra_u = { .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .cia_min_keysize = XTEA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .cia_max_keysize = XTEA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .cia_setkey = xtea_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .cia_encrypt = xtea_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .cia_decrypt = xtea_decrypt } }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .cra_name = "xeta",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .cra_driver_name = "xeta-generic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .cra_blocksize = XTEA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .cra_ctxsize = sizeof (struct xtea_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .cra_alignmask = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .cra_u = { .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .cia_min_keysize = XTEA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .cia_max_keysize = XTEA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .cia_setkey = xtea_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .cia_encrypt = xeta_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .cia_decrypt = xeta_decrypt } }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int __init tea_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return crypto_register_algs(tea_algs, ARRAY_SIZE(tea_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static void __exit tea_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) crypto_unregister_algs(tea_algs, ARRAY_SIZE(tea_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_ALIAS_CRYPTO("tea");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_ALIAS_CRYPTO("xtea");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_ALIAS_CRYPTO("xeta");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) subsys_initcall(tea_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) module_exit(tea_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_DESCRIPTION("TEA, XTEA & XETA Cryptographic Algorithms");