diff options
| author | Aaron Grothe <ajgrothe@yahoo.com> | 2005-09-01 20:42:46 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2005-09-01 20:42:46 -0400 |
| commit | fb4f10ed50f01b0f953068456bfb6e2885921b01 (patch) | |
| tree | e9eb4112522d7969fdc4bbf6455b6d0d59426121 | |
| parent | 75c80c382fbd08acf06fbef9d54c9844e806a8b4 (diff) | |
[CRYPTO]: Fix XTEA implementation
The XTEA implementation was incorrect due to a misinterpretation of
operator precedence. Because of the wide-spread nature of this
error, the erroneous implementation will be kept, albeit under the
new name of XETA.
Signed-off-by: Aaron Grothe <ajgrothe@yahoo.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | Documentation/crypto/api-intro.txt | 1 | ||||
| -rw-r--r-- | crypto/Kconfig | 5 | ||||
| -rw-r--r-- | crypto/tcrypt.c | 11 | ||||
| -rw-r--r-- | crypto/tcrypt.h | 138 | ||||
| -rw-r--r-- | crypto/tea.c | 81 |
5 files changed, 207 insertions, 29 deletions
diff --git a/Documentation/crypto/api-intro.txt b/Documentation/crypto/api-intro.txt index a2d5b4900772..74dffc68ff9f 100644 --- a/Documentation/crypto/api-intro.txt +++ b/Documentation/crypto/api-intro.txt | |||
| @@ -223,6 +223,7 @@ CAST5 algorithm contributors: | |||
| 223 | 223 | ||
| 224 | TEA/XTEA algorithm contributors: | 224 | TEA/XTEA algorithm contributors: |
| 225 | Aaron Grothe | 225 | Aaron Grothe |
| 226 | Michael Ringe | ||
| 226 | 227 | ||
| 227 | Khazad algorithm contributors: | 228 | Khazad algorithm contributors: |
| 228 | Aaron Grothe | 229 | Aaron Grothe |
diff --git a/crypto/Kconfig b/crypto/Kconfig index 256c0b1fed10..89299f4ffe12 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
| @@ -219,7 +219,7 @@ config CRYPTO_CAST6 | |||
| 219 | described in RFC2612. | 219 | described in RFC2612. |
| 220 | 220 | ||
| 221 | config CRYPTO_TEA | 221 | config CRYPTO_TEA |
| 222 | tristate "TEA and XTEA cipher algorithms" | 222 | tristate "TEA, XTEA and XETA cipher algorithms" |
| 223 | depends on CRYPTO | 223 | depends on CRYPTO |
| 224 | help | 224 | help |
| 225 | TEA cipher algorithm. | 225 | TEA cipher algorithm. |
| @@ -232,6 +232,9 @@ config CRYPTO_TEA | |||
| 232 | the TEA algorithm to address a potential key weakness | 232 | the TEA algorithm to address a potential key weakness |
| 233 | in the TEA algorithm. | 233 | in the TEA algorithm. |
| 234 | 234 | ||
| 235 | Xtendend Encryption Tiny Algorithm is a mis-implementation | ||
| 236 | of the XTEA algorithm for compatibility purposes. | ||
| 237 | |||
| 235 | config CRYPTO_ARC4 | 238 | config CRYPTO_ARC4 |
| 236 | tristate "ARC4 cipher algorithm" | 239 | tristate "ARC4 cipher algorithm" |
| 237 | depends on CRYPTO | 240 | depends on CRYPTO |
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index bd7524cfff33..68639419c5bd 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
| @@ -72,7 +72,7 @@ static char *check[] = { | |||
| 72 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", | 72 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", |
| 73 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", | 73 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", |
| 74 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | 74 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
| 75 | "khazad", "wp512", "wp384", "wp256", "tnepres", NULL | 75 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | static void hexdump(unsigned char *buf, unsigned int len) | 78 | static void hexdump(unsigned char *buf, unsigned int len) |
| @@ -859,6 +859,10 @@ static void do_test(void) | |||
| 859 | test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS); | 859 | test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS); |
| 860 | test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS); | 860 | test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS); |
| 861 | 861 | ||
| 862 | //XETA | ||
| 863 | test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS); | ||
| 864 | test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS); | ||
| 865 | |||
| 862 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); | 866 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
| 863 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); | 867 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
| 864 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); | 868 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); |
| @@ -1016,6 +1020,11 @@ static void do_test(void) | |||
| 1016 | case 29: | 1020 | case 29: |
| 1017 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); | 1021 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
| 1018 | break; | 1022 | break; |
| 1023 | |||
| 1024 | case 30: | ||
| 1025 | test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS); | ||
| 1026 | test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS); | ||
| 1027 | break; | ||
| 1019 | 1028 | ||
| 1020 | #ifdef CONFIG_CRYPTO_HMAC | 1029 | #ifdef CONFIG_CRYPTO_HMAC |
| 1021 | case 100: | 1030 | case 100: |
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h index c01a0ce9b40a..522ffd4b6f43 100644 --- a/crypto/tcrypt.h +++ b/crypto/tcrypt.h | |||
| @@ -2211,7 +2211,7 @@ static struct cipher_testvec xtea_enc_tv_template[] = { | |||
| 2211 | .klen = 16, | 2211 | .klen = 16, |
| 2212 | .input = { [0 ... 8] = 0x00 }, | 2212 | .input = { [0 ... 8] = 0x00 }, |
| 2213 | .ilen = 8, | 2213 | .ilen = 8, |
| 2214 | .result = { 0xaa, 0x22, 0x96, 0xe5, 0x6c, 0x61, 0xf3, 0x45 }, | 2214 | .result = { 0xd8, 0xd4, 0xe9, 0xde, 0xd9, 0x1e, 0x13, 0xf7 }, |
| 2215 | .rlen = 8, | 2215 | .rlen = 8, |
| 2216 | }, { | 2216 | }, { |
| 2217 | .key = { 0x2b, 0x02, 0x05, 0x68, 0x06, 0x14, 0x49, 0x76, | 2217 | .key = { 0x2b, 0x02, 0x05, 0x68, 0x06, 0x14, 0x49, 0x76, |
| @@ -2219,31 +2219,31 @@ static struct cipher_testvec xtea_enc_tv_template[] = { | |||
| 2219 | .klen = 16, | 2219 | .klen = 16, |
| 2220 | .input = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x65, 0x2e }, | 2220 | .input = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x65, 0x2e }, |
| 2221 | .ilen = 8, | 2221 | .ilen = 8, |
| 2222 | .result = { 0x82, 0x3e, 0xeb, 0x35, 0xdc, 0xdd, 0xd9, 0xc3 }, | 2222 | .result = { 0x94, 0xeb, 0xc8, 0x96, 0x84, 0x6a, 0x49, 0xa8 }, |
| 2223 | .rlen = 8, | 2223 | .rlen = 8, |
| 2224 | }, { | 2224 | }, { |
| 2225 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | 2225 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, |
| 2226 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | 2226 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, |
| 2227 | .klen = 16, | 2227 | .klen = 16, |
| 2228 | .input = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | 2228 | .input = { 0x3e, 0xce, 0xae, 0x22, 0x60, 0x56, 0xa8, 0x9d, |
| 2229 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | 2229 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, |
| 2230 | .ilen = 16, | 2230 | .ilen = 16, |
| 2231 | .result = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, | 2231 | .result = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, |
| 2232 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, | 2232 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, |
| 2233 | .rlen = 16, | 2233 | .rlen = 16, |
| 2234 | }, { | 2234 | }, { |
| 2235 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | 2235 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, |
| 2236 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | 2236 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, |
| 2237 | .klen = 16, | 2237 | .klen = 16, |
| 2238 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | 2238 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, |
| 2239 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | 2239 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, |
| 2240 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | 2240 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, |
| 2241 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | 2241 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, |
| 2242 | .ilen = 32, | 2242 | .ilen = 32, |
| 2243 | .result = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, | 2243 | .result = { 0x99, 0x81, 0x9f, 0x5d, 0x6f, 0x4b, 0x31, 0x3a, |
| 2244 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, | 2244 | 0x86, 0xff, 0x6f, 0xd0, 0xe3, 0x87, 0x70, 0x07, |
| 2245 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, | 2245 | 0x4d, 0xb8, 0xcf, 0xf3, 0x99, 0x50, 0xb3, 0xd4, |
| 2246 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, | 2246 | 0x73, 0xa2, 0xfa, 0xc9, 0x16, 0x59, 0x5d, 0x81 }, |
| 2247 | .rlen = 32, | 2247 | .rlen = 32, |
| 2248 | } | 2248 | } |
| 2249 | }; | 2249 | }; |
| @@ -2252,7 +2252,7 @@ static struct cipher_testvec xtea_dec_tv_template[] = { | |||
| 2252 | { | 2252 | { |
| 2253 | .key = { [0 ... 15] = 0x00 }, | 2253 | .key = { [0 ... 15] = 0x00 }, |
| 2254 | .klen = 16, | 2254 | .klen = 16, |
| 2255 | .input = { 0xaa, 0x22, 0x96, 0xe5, 0x6c, 0x61, 0xf3, 0x45 }, | 2255 | .input = { 0xd8, 0xd4, 0xe9, 0xde, 0xd9, 0x1e, 0x13, 0xf7 }, |
| 2256 | .ilen = 8, | 2256 | .ilen = 8, |
| 2257 | .result = { [0 ... 8] = 0x00 }, | 2257 | .result = { [0 ... 8] = 0x00 }, |
| 2258 | .rlen = 8, | 2258 | .rlen = 8, |
| @@ -2260,7 +2260,7 @@ static struct cipher_testvec xtea_dec_tv_template[] = { | |||
| 2260 | .key = { 0x2b, 0x02, 0x05, 0x68, 0x06, 0x14, 0x49, 0x76, | 2260 | .key = { 0x2b, 0x02, 0x05, 0x68, 0x06, 0x14, 0x49, 0x76, |
| 2261 | 0x77, 0x5d, 0x0e, 0x26, 0x6c, 0x28, 0x78, 0x43 }, | 2261 | 0x77, 0x5d, 0x0e, 0x26, 0x6c, 0x28, 0x78, 0x43 }, |
| 2262 | .klen = 16, | 2262 | .klen = 16, |
| 2263 | .input = { 0x82, 0x3e, 0xeb, 0x35, 0xdc, 0xdd, 0xd9, 0xc3 }, | 2263 | .input = { 0x94, 0xeb, 0xc8, 0x96, 0x84, 0x6a, 0x49, 0xa8 }, |
| 2264 | .ilen = 8, | 2264 | .ilen = 8, |
| 2265 | .result = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x65, 0x2e }, | 2265 | .result = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x65, 0x2e }, |
| 2266 | .rlen = 8, | 2266 | .rlen = 8, |
| @@ -2268,24 +2268,24 @@ static struct cipher_testvec xtea_dec_tv_template[] = { | |||
| 2268 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | 2268 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, |
| 2269 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | 2269 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, |
| 2270 | .klen = 16, | 2270 | .klen = 16, |
| 2271 | .input = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, | 2271 | .input = { 0x3e, 0xce, 0xae, 0x22, 0x60, 0x56, 0xa8, 0x9d, |
| 2272 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, | 2272 | 0x77, 0x4d, 0xd4, 0xb4, 0x87, 0x24, 0xe3, 0x9a }, |
| 2273 | .ilen = 16, | 2273 | .ilen = 16, |
| 2274 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | 2274 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, |
| 2275 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | 2275 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, |
| 2276 | .rlen = 16, | 2276 | .rlen = 16, |
| 2277 | }, { | 2277 | }, { |
| 2278 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | 2278 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, |
| 2279 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | 2279 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, |
| 2280 | .klen = 16, | 2280 | .klen = 16, |
| 2281 | .input = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, | 2281 | .input = { 0x99, 0x81, 0x9f, 0x5d, 0x6f, 0x4b, 0x31, 0x3a, |
| 2282 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, | 2282 | 0x86, 0xff, 0x6f, 0xd0, 0xe3, 0x87, 0x70, 0x07, |
| 2283 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, | 2283 | 0x4d, 0xb8, 0xcf, 0xf3, 0x99, 0x50, 0xb3, 0xd4, |
| 2284 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, | 2284 | 0x73, 0xa2, 0xfa, 0xc9, 0x16, 0x59, 0x5d, 0x81 }, |
| 2285 | .ilen = 32, | 2285 | .ilen = 32, |
| 2286 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | 2286 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, |
| 2287 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | 2287 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, |
| 2288 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | 2288 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, |
| 2289 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | 2289 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, |
| 2290 | .rlen = 32, | 2290 | .rlen = 32, |
| 2291 | } | 2291 | } |
| @@ -2594,6 +2594,98 @@ static struct cipher_testvec anubis_cbc_dec_tv_template[] = { | |||
| 2594 | }, | 2594 | }, |
| 2595 | }; | 2595 | }; |
| 2596 | 2596 | ||
| 2597 | /* | ||
| 2598 | * XETA test vectors | ||
| 2599 | */ | ||
| 2600 | #define XETA_ENC_TEST_VECTORS 4 | ||
| 2601 | #define XETA_DEC_TEST_VECTORS 4 | ||
| 2602 | |||
| 2603 | static struct cipher_testvec xeta_enc_tv_template[] = { | ||
| 2604 | { | ||
| 2605 | .key = { [0 ... 15] = 0x00 }, | ||
| 2606 | .klen = 16, | ||
| 2607 | .input = { [0 ... 8] = 0x00 }, | ||
| 2608 | .ilen = 8, | ||
| 2609 | .result = { 0xaa, 0x22, 0x96, 0xe5, 0x6c, 0x61, 0xf3, 0x45 }, | ||
| 2610 | .rlen = 8, | ||
| 2611 | }, { | ||
| 2612 | .key = { 0x2b, 0x02, 0x05, 0x68, 0x06, 0x14, 0x49, 0x76, | ||
| 2613 | 0x77, 0x5d, 0x0e, 0x26, 0x6c, 0x28, 0x78, 0x43 }, | ||
| 2614 | .klen = 16, | ||
| 2615 | .input = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x65, 0x2e }, | ||
| 2616 | .ilen = 8, | ||
| 2617 | .result = { 0x82, 0x3e, 0xeb, 0x35, 0xdc, 0xdd, 0xd9, 0xc3 }, | ||
| 2618 | .rlen = 8, | ||
| 2619 | }, { | ||
| 2620 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | ||
| 2621 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | ||
| 2622 | .klen = 16, | ||
| 2623 | .input = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | ||
| 2624 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | ||
| 2625 | .ilen = 16, | ||
| 2626 | .result = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, | ||
| 2627 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, | ||
| 2628 | .rlen = 16, | ||
| 2629 | }, { | ||
| 2630 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | ||
| 2631 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | ||
| 2632 | .klen = 16, | ||
| 2633 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | ||
| 2634 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | ||
| 2635 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | ||
| 2636 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | ||
| 2637 | .ilen = 32, | ||
| 2638 | .result = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, | ||
| 2639 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, | ||
| 2640 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, | ||
| 2641 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, | ||
| 2642 | .rlen = 32, | ||
| 2643 | } | ||
| 2644 | }; | ||
| 2645 | |||
| 2646 | static struct cipher_testvec xeta_dec_tv_template[] = { | ||
| 2647 | { | ||
| 2648 | .key = { [0 ... 15] = 0x00 }, | ||
| 2649 | .klen = 16, | ||
| 2650 | .input = { 0xaa, 0x22, 0x96, 0xe5, 0x6c, 0x61, 0xf3, 0x45 }, | ||
| 2651 | .ilen = 8, | ||
| 2652 | .result = { [0 ... 8] = 0x00 }, | ||
| 2653 | .rlen = 8, | ||
| 2654 | }, { | ||
| 2655 | .key = { 0x2b, 0x02, 0x05, 0x68, 0x06, 0x14, 0x49, 0x76, | ||
| 2656 | 0x77, 0x5d, 0x0e, 0x26, 0x6c, 0x28, 0x78, 0x43 }, | ||
| 2657 | .klen = 16, | ||
| 2658 | .input = { 0x82, 0x3e, 0xeb, 0x35, 0xdc, 0xdd, 0xd9, 0xc3 }, | ||
| 2659 | .ilen = 8, | ||
| 2660 | .result = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x65, 0x2e }, | ||
| 2661 | .rlen = 8, | ||
| 2662 | }, { | ||
| 2663 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | ||
| 2664 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | ||
| 2665 | .klen = 16, | ||
| 2666 | .input = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, | ||
| 2667 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, | ||
| 2668 | .ilen = 16, | ||
| 2669 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | ||
| 2670 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | ||
| 2671 | .rlen = 16, | ||
| 2672 | }, { | ||
| 2673 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | ||
| 2674 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | ||
| 2675 | .klen = 16, | ||
| 2676 | .input = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, | ||
| 2677 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, | ||
| 2678 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, | ||
| 2679 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, | ||
| 2680 | .ilen = 32, | ||
| 2681 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | ||
| 2682 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | ||
| 2683 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | ||
| 2684 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | ||
| 2685 | .rlen = 32, | ||
| 2686 | } | ||
| 2687 | }; | ||
| 2688 | |||
| 2597 | /* | 2689 | /* |
| 2598 | * Compression stuff. | 2690 | * Compression stuff. |
| 2599 | */ | 2691 | */ |
diff --git a/crypto/tea.c b/crypto/tea.c index 03c23cbd3afa..5924efdd3a16 100644 --- a/crypto/tea.c +++ b/crypto/tea.c | |||
| @@ -1,11 +1,15 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Cryptographic API. | 2 | * Cryptographic API. |
| 3 | * | 3 | * |
| 4 | * TEA and Xtended TEA Algorithms | 4 | * TEA, XTEA, and XETA crypto alogrithms |
| 5 | * | 5 | * |
| 6 | * The TEA and Xtended TEA algorithms were developed by David Wheeler | 6 | * The TEA and Xtended TEA algorithms were developed by David Wheeler |
| 7 | * and Roger Needham at the Computer Laboratory of Cambridge University. | 7 | * and Roger Needham at the Computer Laboratory of Cambridge University. |
| 8 | * | 8 | * |
| 9 | * Due to the order of evaluation in XTEA many people have incorrectly | ||
| 10 | * implemented it. XETA (XTEA in the wrong order), exists for | ||
| 11 | * compatibility with these implementations. | ||
| 12 | * | ||
| 9 | * Copyright (c) 2004 Aaron Grothe ajgrothe@yahoo.com | 13 | * Copyright (c) 2004 Aaron Grothe ajgrothe@yahoo.com |
| 10 | * | 14 | * |
| 11 | * This program is free software; you can redistribute it and/or modify | 15 | * This program is free software; you can redistribute it and/or modify |
| @@ -153,9 +157,9 @@ static void xtea_encrypt(void *ctx_arg, u8 *dst, const u8 *src) | |||
| 153 | z = u32_in (src + 4); | 157 | z = u32_in (src + 4); |
| 154 | 158 | ||
| 155 | while (sum != limit) { | 159 | while (sum != limit) { |
| 156 | y += (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum&3]; | 160 | y += ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->KEY[sum&3]); |
| 157 | sum += XTEA_DELTA; | 161 | sum += XTEA_DELTA; |
| 158 | z += (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 &3]; | 162 | z += ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->KEY[sum>>11 &3]); |
| 159 | } | 163 | } |
| 160 | 164 | ||
| 161 | u32_out (dst, y); | 165 | u32_out (dst, y); |
| @@ -175,6 +179,51 @@ static void xtea_decrypt(void *ctx_arg, u8 *dst, const u8 *src) | |||
| 175 | sum = XTEA_DELTA * XTEA_ROUNDS; | 179 | sum = XTEA_DELTA * XTEA_ROUNDS; |
| 176 | 180 | ||
| 177 | while (sum) { | 181 | while (sum) { |
| 182 | z -= ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->KEY[sum>>11 & 3]); | ||
| 183 | sum -= XTEA_DELTA; | ||
| 184 | y -= ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->KEY[sum & 3]); | ||
| 185 | } | ||
| 186 | |||
| 187 | u32_out (dst, y); | ||
| 188 | u32_out (dst + 4, z); | ||
| 189 | |||
| 190 | } | ||
| 191 | |||
| 192 | |||
| 193 | static void xeta_encrypt(void *ctx_arg, u8 *dst, const u8 *src) | ||
| 194 | { | ||
| 195 | |||
| 196 | u32 y, z, sum = 0; | ||
| 197 | u32 limit = XTEA_DELTA * XTEA_ROUNDS; | ||
| 198 | |||
| 199 | struct xtea_ctx *ctx = ctx_arg; | ||
| 200 | |||
| 201 | y = u32_in (src); | ||
| 202 | z = u32_in (src + 4); | ||
| 203 | |||
| 204 | while (sum != limit) { | ||
| 205 | y += (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum&3]; | ||
| 206 | sum += XTEA_DELTA; | ||
| 207 | z += (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 &3]; | ||
| 208 | } | ||
| 209 | |||
| 210 | u32_out (dst, y); | ||
| 211 | u32_out (dst + 4, z); | ||
| 212 | |||
| 213 | } | ||
| 214 | |||
| 215 | static void xeta_decrypt(void *ctx_arg, u8 *dst, const u8 *src) | ||
| 216 | { | ||
| 217 | |||
| 218 | u32 y, z, sum; | ||
| 219 | struct tea_ctx *ctx = ctx_arg; | ||
| 220 | |||
| 221 | y = u32_in (src); | ||
| 222 | z = u32_in (src + 4); | ||
| 223 | |||
| 224 | sum = XTEA_DELTA * XTEA_ROUNDS; | ||
| 225 | |||
| 226 | while (sum) { | ||
| 178 | z -= (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 & 3]; | 227 | z -= (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 & 3]; |
| 179 | sum -= XTEA_DELTA; | 228 | sum -= XTEA_DELTA; |
| 180 | y -= (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum & 3]; | 229 | y -= (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum & 3]; |
| @@ -215,6 +264,21 @@ static struct crypto_alg xtea_alg = { | |||
| 215 | .cia_decrypt = xtea_decrypt } } | 264 | .cia_decrypt = xtea_decrypt } } |
| 216 | }; | 265 | }; |
| 217 | 266 | ||
| 267 | static struct crypto_alg xeta_alg = { | ||
| 268 | .cra_name = "xeta", | ||
| 269 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | ||
| 270 | .cra_blocksize = XTEA_BLOCK_SIZE, | ||
| 271 | .cra_ctxsize = sizeof (struct xtea_ctx), | ||
| 272 | .cra_module = THIS_MODULE, | ||
| 273 | .cra_list = LIST_HEAD_INIT(xtea_alg.cra_list), | ||
| 274 | .cra_u = { .cipher = { | ||
| 275 | .cia_min_keysize = XTEA_KEY_SIZE, | ||
| 276 | .cia_max_keysize = XTEA_KEY_SIZE, | ||
| 277 | .cia_setkey = xtea_setkey, | ||
| 278 | .cia_encrypt = xeta_encrypt, | ||
| 279 | .cia_decrypt = xeta_decrypt } } | ||
| 280 | }; | ||
| 281 | |||
| 218 | static int __init init(void) | 282 | static int __init init(void) |
| 219 | { | 283 | { |
| 220 | int ret = 0; | 284 | int ret = 0; |
| @@ -229,6 +293,13 @@ static int __init init(void) | |||
| 229 | goto out; | 293 | goto out; |
| 230 | } | 294 | } |
| 231 | 295 | ||
| 296 | ret = crypto_register_alg(&xeta_alg); | ||
| 297 | if (ret < 0) { | ||
| 298 | crypto_unregister_alg(&tea_alg); | ||
| 299 | crypto_unregister_alg(&xtea_alg); | ||
| 300 | goto out; | ||
| 301 | } | ||
| 302 | |||
| 232 | out: | 303 | out: |
| 233 | return ret; | 304 | return ret; |
| 234 | } | 305 | } |
| @@ -237,12 +308,14 @@ static void __exit fini(void) | |||
| 237 | { | 308 | { |
| 238 | crypto_unregister_alg(&tea_alg); | 309 | crypto_unregister_alg(&tea_alg); |
| 239 | crypto_unregister_alg(&xtea_alg); | 310 | crypto_unregister_alg(&xtea_alg); |
| 311 | crypto_unregister_alg(&xeta_alg); | ||
| 240 | } | 312 | } |
| 241 | 313 | ||
| 242 | MODULE_ALIAS("xtea"); | 314 | MODULE_ALIAS("xtea"); |
| 315 | MODULE_ALIAS("xeta"); | ||
| 243 | 316 | ||
| 244 | module_init(init); | 317 | module_init(init); |
| 245 | module_exit(fini); | 318 | module_exit(fini); |
| 246 | 319 | ||
| 247 | MODULE_LICENSE("GPL"); | 320 | MODULE_LICENSE("GPL"); |
| 248 | MODULE_DESCRIPTION("TEA & XTEA Cryptographic Algorithms"); | 321 | MODULE_DESCRIPTION("TEA, XTEA & XETA Cryptographic Algorithms"); |
