45 #include <asm/byteorder.h>
46 #include <linux/bitops.h>
48 #include <linux/module.h>
58 #define ror56(hi, lo, n) \
60 u32 t = lo & ((1 << n) - 1); \
61 lo = (lo >> n) | ((hi & ((1 << n) - 1)) << (32 - n)); \
62 hi = (hi >> n) | (t << (24-n)); \
66 #define ror56_64(k, n) \
68 k = (k >> n) | ((k & ((1 << n) - 1)) << (56 - n)); \
76 #define Z(x) cpu_to_be32(x << 3)
77 static const __be32 sbox0[256] = {
78 Z(0xea),
Z(0x7f),
Z(0xb2),
Z(0x64),
Z(0x9d),
Z(0xb0),
Z(0xd9),
Z(0x11),
79 Z(0xcd),
Z(0
x86),
Z(0
x86),
Z(0x91),
Z(0x0a),
Z(0xb2),
Z(0x93),
Z(0x06),
80 Z(0x0e),
Z(0x06),
Z(0xd2),
Z(0x65),
Z(0x73),
Z(0xc5),
Z(0x28),
Z(0x60),
81 Z(0xf2),
Z(0x20),
Z(0xb5),
Z(0x38),
Z(0x7e),
Z(0xda),
Z(0x9f),
Z(0xe3),
82 Z(0xd2),
Z(0xcf),
Z(0xc4),
Z(0x3c),
Z(0x61),
Z(0xff),
Z(0x4a),
Z(0x4a),
83 Z(0x35),
Z(0xac),
Z(0xaa),
Z(0x5f),
Z(0x2b),
Z(0xbb),
Z(0xbc),
Z(0x53),
84 Z(0x4e),
Z(0x9d),
Z(0x78),
Z(0xa3),
Z(0xdc),
Z(0x09),
Z(0x32),
Z(0x10),
85 Z(0xc6),
Z(0x6f),
Z(0x66),
Z(0xd6),
Z(0xab),
Z(0xa9),
Z(0xaf),
Z(0xfd),
86 Z(0x3b),
Z(0x95),
Z(0xe8),
Z(0x34),
Z(0x9a),
Z(0x81),
Z(0x72),
Z(0x80),
87 Z(0x9c),
Z(0xf3),
Z(0xec),
Z(0xda),
Z(0x9f),
Z(0x26),
Z(0x76),
Z(0x15),
88 Z(0x3e),
Z(0x55),
Z(0x4d),
Z(0xde),
Z(0x84),
Z(0xee),
Z(0
xad),
Z(0xc7),
89 Z(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xe1),
Z(0x0e),
Z(0x76),
Z(0xe5),
104 Z(0x36),
Z(0x4f),
Z(0x59),
Z(0xc7),
Z(0x08),
Z(0x6e),
Z(0x82),
Z(0xa6),
105 Z(0x93),
Z(0xc4),
Z(0xaa),
Z(0x26),
Z(0x49),
Z(0xe0),
Z(0x21),
Z(0x64),
106 Z(0x07),
Z(0x9f),
Z(0x64),
Z(0x81),
Z(0x9c),
Z(0xbf),
Z(0xf9),
Z(0xd1),
107 Z(0x43),
Z(0xf8),
Z(0xb6),
Z(0xb9),
Z(0xf1),
Z(0x24),
Z(0x75),
Z(0x03),
108 Z(0xe4),
Z(0xb0),
Z(0x99),
Z(0x46),
Z(0x3d),
Z(0xf5),
Z(0xd1),
Z(0x39),
109 Z(0x72),
Z(0x12),
Z(0xf6),
Z(0xba),
Z(0x0c),
Z(0x0d),
Z(0x42),
Z(0x2e)
113 #define Z(x) cpu_to_be32((x << 27) | (x >> 5))
114 static const __be32 sbox1[256] = {
115 Z(0x77),
Z(0x14),
Z(0xa6),
Z(0xfe),
Z(0xb2),
Z(0x5e),
Z(0x8c),
Z(0x3e),
116 Z(0x67),
Z(0x6c),
Z(0xa1),
Z(0x0d),
Z(0xc2),
Z(0xa2),
Z(0xc1),
Z(0x85),
117 Z(0x6c),
Z(0x7b),
Z(0x67),
Z(0xc6),
Z(0x23),
Z(0xe3),
Z(0xf2),
Z(0x89),
118 Z(0x50),
Z(0x9c),
Z(0x03),
Z(0xb7),
Z(0x73),
Z(0xe6),
Z(0xe1),
Z(0x39),
119 Z(0x31),
Z(0x2c),
Z(0x27),
Z(0x9f),
Z(0xa5),
Z(0x69),
Z(0x44),
Z(0xd6),
120 Z(0x23),
Z(0x83),
Z(0x98),
Z(0x7d),
Z(0x3c),
Z(0xb4),
Z(0x2d),
Z(0x99),
121 Z(0x1c),
Z(0x1f),
Z(0x8c),
Z(0x20),
Z(0x03),
Z(0x7c),
Z(0x5f),
Z(0
xad),
122 Z(0xf4),
Z(0xfa),
Z(0x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Z(0x52),
137 Z(0xf5),
Z(0x1e),
Z(0xf4),
Z(0xcb),
Z(0x18),
Z(0x33),
Z(0x1f),
Z(0xf8),
138 Z(0x69),
Z(0x10),
Z(0x9d),
Z(0xd3),
Z(0xf7),
Z(0x28),
Z(0xf8),
Z(0x30),
139 Z(0x05),
Z(0x5e),
Z(0x32),
Z(0xc0),
Z(0xd5),
Z(0x19),
Z(0xbd),
Z(0x45),
140 Z(0x8b),
Z(0x5b),
Z(0xfd),
Z(0xbc),
Z(0xe2),
Z(0x5c),
Z(0xa9),
Z(0x96),
141 Z(0xef),
Z(0x70),
Z(0xcf),
Z(0xc2),
Z(0x2a),
Z(0xb3),
Z(0x61),
Z(0
xad),
142 Z(0x80),
Z(0x48),
Z(0x81),
Z(0xb7),
Z(0x1d),
Z(0x43),
Z(0xd9),
Z(0xd7),
143 Z(0x45),
Z(0xf0),
Z(0xd8),
Z(0x8a),
Z(0x59),
Z(0x7c),
Z(0x57),
Z(0xc1),
144 Z(0x79),
Z(0xc7),
Z(0x34),
Z(0xd6),
Z(0x43),
Z(0xdf),
Z(0xe4),
Z(0x78),
145 Z(0x16),
Z(0x06),
Z(0xda),
Z(0x92),
Z(0x76),
Z(0x51),
Z(0xe1),
Z(0xd4),
146 Z(0x70),
Z(0x03),
Z(0xe0),
Z(0x2f),
Z(0x96),
Z(0x91),
Z(0x82),
Z(0x80)
150 #define Z(x) cpu_to_be32(x << 11)
151 static const __be32 sbox2[256] = {
152 Z(0xf0),
Z(0x37),
Z(0x24),
Z(0x53),
Z(0x2a),
Z(0x03),
Z(0x83),
Z(0
x86),
153 Z(0xd1),
Z(0xec),
Z(0x50),
Z(0xf0),
Z(0x42),
Z(0x78),
Z(0x2f),
Z(0x6d),
154 Z(0xbf),
Z(0x80),
Z(0x87),
Z(0x27),
Z(0x95),
Z(0xe2),
Z(0xc5),
Z(0x5d),
155 Z(0xf9),
Z(0x6f),
Z(0xdb),
Z(0xb4),
Z(0x65),
Z(0x6e),
Z(0xe7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
Z(0x8f),
Z(0x80),
Z(0x0f),
Z(0xce),
Z(0x0b),
Z(0x5e),
171 Z(0xb7),
Z(0x5e),
Z(0xac),
Z(0x24),
Z(0x94),
Z(0x4a),
Z(0x18),
Z(0x15),
172 Z(0x05),
Z(0xe8),
Z(0x02),
Z(0x77),
Z(0xa9),
Z(0xc7),
Z(0x40),
Z(0x45),
173 Z(0x89),
Z(0xd1),
Z(0xea),
Z(0xde),
Z(0x0c),
Z(0x79),
Z(0x2a),
Z(0x99),
174 Z(0x6c),
Z(0x3e),
Z(0x95),
Z(0xdd),
Z(0x8c),
Z(0x7d),
Z(0
xad),
Z(0x6f),
175 Z(0xdc),
Z(0xff),
Z(0xfd),
Z(0x62),
Z(0x47),
Z(0xb3),
Z(0x21),
Z(0x8a),
176 Z(0xec),
Z(0x8e),
Z(0x19),
Z(0x18),
Z(0xb4),
Z(0x6e),
Z(0x3d),
Z(0xfd),
177 Z(0x74),
Z(0x54),
Z(0x1e),
Z(0x04),
Z(0x85),
Z(0xd8),
Z(0xbc),
Z(0x1f),
178 Z(0x56),
Z(0xe7),
Z(0x3a),
Z(0x56),
Z(0x67),
Z(0xd6),
Z(0xc8),
Z(0xa5),
179 Z(0xf3),
Z(0x8e),
Z(0xde),
Z(0xae),
Z(0x37),
Z(0x49),
Z(0xb7),
Z(0xfa),
180 Z(0xc8),
Z(0xf4),
Z(0x1f),
Z(0xe0),
Z(0x2a),
Z(0x9b),
Z(0x15),
Z(0xd1),
181 Z(0x34),
Z(0x0e),
Z(0xb5),
Z(0xe0),
Z(0x44),
Z(0x78),
Z(0x84),
Z(0x59),
182 Z(0x56),
Z(0x68),
Z(0x77),
Z(0xa5),
Z(0x14),
Z(0x06),
Z(0xf5),
Z(0x2f),
183 Z(0x8c),
Z(0x8a),
Z(0x73),
Z(0x80),
Z(0x76),
Z(0xb4),
Z(0x10),
Z(0
x86)
187 #define Z(x) cpu_to_be32(x << 19)
188 static const __be32 sbox3[256] = {
189 Z(0xa9),
Z(0x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0x95),
Z(0x49),
Z(0xcf),
Z(0xc3),
Z(0x1d),
Z(0x8f),
219 Z(0xd8),
Z(0xe1),
Z(0x73),
Z(0xdb),
Z(0
xad),
Z(0xc8),
Z(0xc9),
Z(0xa9),
220 Z(0xa1),
Z(0xc2),
Z(0xc5),
Z(0xe3),
Z(0xba),
Z(0xfc),
Z(0x0e),
Z(0x25)
226 #define F_ENCRYPT(R, L, sched) \
228 union lc4 { __be32 l; u8 c[4]; } u; \
230 L ^= sbox0[u.c[0]] ^ sbox1[u.c[1]] ^ sbox2[u.c[2]] ^ sbox3[u.c[3]]; \
303 static int fcrypt_setkey(
struct crypto_tfm *tfm,
const u8 *
key,
unsigned int keylen)
307 #if BITS_PER_LONG == 64
393 .cra_name =
"fcrypt",
399 .cra_u = { .cipher = {
400 .cia_min_keysize = 8,
401 .cia_max_keysize = 8,
402 .cia_setkey = fcrypt_setkey,
403 .cia_encrypt = fcrypt_encrypt,
404 .cia_decrypt = fcrypt_decrypt } }
407 static int __init fcrypt_mod_init(
void)
412 static void __exit fcrypt_mod_fini(
void)