Procházet zdrojové kódy

Merge pull request #506 from libtom/add-tea

Add TEA blockcipher
Steffen Jaeckel před 6 roky
rodič
revize
659540393e

+ 2 - 1
doc/crypt.tex

@@ -600,7 +600,7 @@ As of this release the current cipher\_descriptors elements are the following:
 \index{Cipher descriptor table}
 \index{blowfish\_desc} \index{xtea\_desc} \index{rc2\_desc} \index{rc5\_desc} \index{rc6\_desc} \index{saferp\_desc} \index{aes\_desc} \index{twofish\_desc}
 \index{des\_desc} \index{des3\_desc} \index{noekeon\_desc} \index{skipjack\_desc} \index{anubis\_desc} \index{khazad\_desc} \index{kseed\_desc} \index{kasumi\_desc} \index{camellia\_desc} \index{aes\_enc\_desc}
-\index{idea\_desc} \index{serpent\_desc}
+\index{idea\_desc} \index{serpent\_desc} \index{tea\_desc}
 \begin{figure}[hpbt]
 \begin{small}
 \begin{center}
@@ -627,6 +627,7 @@ As of this release the current cipher\_descriptors elements are the following:
      \hline Camellia & camellia\_desc & 16 & 16, 24, 32 & 18, 24 \\
      \hline IDEA & idea\_desc & 8 & 16 & 8 \\
      \hline Serpent & serpent\_desc & 16 & 16, 24, 32 & 32 \\
+     \hline TEA & tea\_desc & 8 & 16 & 32 \\
      \hline
 \end{tabular}
 \end{center}

+ 4 - 0
libtomcrypt_VS2008.vcproj

@@ -395,6 +395,10 @@
 				RelativePath="src\ciphers\skipjack.c"
 				>
 			</File>
+			<File
+				RelativePath="src\ciphers\tea.c"
+				>
+			</File>
 			<File
 				RelativePath="src\ciphers\xtea.c"
 				>

+ 4 - 4
makefile.mingw

@@ -39,10 +39,10 @@ OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src
 src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/idea.o src/ciphers/kasumi.o \
 src/ciphers/khazad.o src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o \
 src/ciphers/rc5.o src/ciphers/rc6.o src/ciphers/safer/safer.o src/ciphers/safer/saferp.o \
-src/ciphers/serpent.o src/ciphers/skipjack.o src/ciphers/twofish/twofish.o src/ciphers/xtea.o \
-src/encauth/ccm/ccm_add_aad.o src/encauth/ccm/ccm_add_nonce.o src/encauth/ccm/ccm_done.o \
-src/encauth/ccm/ccm_init.o src/encauth/ccm/ccm_memory.o src/encauth/ccm/ccm_process.o \
-src/encauth/ccm/ccm_reset.o src/encauth/ccm/ccm_test.o \
+src/ciphers/serpent.o src/ciphers/skipjack.o src/ciphers/tea.o src/ciphers/twofish/twofish.o \
+src/ciphers/xtea.o src/encauth/ccm/ccm_add_aad.o src/encauth/ccm/ccm_add_nonce.o \
+src/encauth/ccm/ccm_done.o src/encauth/ccm/ccm_init.o src/encauth/ccm/ccm_memory.o \
+src/encauth/ccm/ccm_process.o src/encauth/ccm/ccm_reset.o src/encauth/ccm/ccm_test.o \
 src/encauth/chachapoly/chacha20poly1305_add_aad.o src/encauth/chachapoly/chacha20poly1305_decrypt.o \
 src/encauth/chachapoly/chacha20poly1305_done.o src/encauth/chachapoly/chacha20poly1305_encrypt.o \
 src/encauth/chachapoly/chacha20poly1305_init.o src/encauth/chachapoly/chacha20poly1305_memory.o \

+ 4 - 4
makefile.msvc

@@ -32,10 +32,10 @@ OBJECTS=src/ciphers/aes/aes.obj src/ciphers/aes/aes_enc.obj src/ciphers/anubis.o
 src/ciphers/camellia.obj src/ciphers/cast5.obj src/ciphers/des.obj src/ciphers/idea.obj src/ciphers/kasumi.obj \
 src/ciphers/khazad.obj src/ciphers/kseed.obj src/ciphers/multi2.obj src/ciphers/noekeon.obj src/ciphers/rc2.obj \
 src/ciphers/rc5.obj src/ciphers/rc6.obj src/ciphers/safer/safer.obj src/ciphers/safer/saferp.obj \
-src/ciphers/serpent.obj src/ciphers/skipjack.obj src/ciphers/twofish/twofish.obj src/ciphers/xtea.obj \
-src/encauth/ccm/ccm_add_aad.obj src/encauth/ccm/ccm_add_nonce.obj src/encauth/ccm/ccm_done.obj \
-src/encauth/ccm/ccm_init.obj src/encauth/ccm/ccm_memory.obj src/encauth/ccm/ccm_process.obj \
-src/encauth/ccm/ccm_reset.obj src/encauth/ccm/ccm_test.obj \
+src/ciphers/serpent.obj src/ciphers/skipjack.obj src/ciphers/tea.obj src/ciphers/twofish/twofish.obj \
+src/ciphers/xtea.obj src/encauth/ccm/ccm_add_aad.obj src/encauth/ccm/ccm_add_nonce.obj \
+src/encauth/ccm/ccm_done.obj src/encauth/ccm/ccm_init.obj src/encauth/ccm/ccm_memory.obj \
+src/encauth/ccm/ccm_process.obj src/encauth/ccm/ccm_reset.obj src/encauth/ccm/ccm_test.obj \
 src/encauth/chachapoly/chacha20poly1305_add_aad.obj src/encauth/chachapoly/chacha20poly1305_decrypt.obj \
 src/encauth/chachapoly/chacha20poly1305_done.obj src/encauth/chachapoly/chacha20poly1305_encrypt.obj \
 src/encauth/chachapoly/chacha20poly1305_init.obj src/encauth/chachapoly/chacha20poly1305_memory.obj \

+ 4 - 4
makefile.unix

@@ -49,10 +49,10 @@ OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src
 src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/idea.o src/ciphers/kasumi.o \
 src/ciphers/khazad.o src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o \
 src/ciphers/rc5.o src/ciphers/rc6.o src/ciphers/safer/safer.o src/ciphers/safer/saferp.o \
-src/ciphers/serpent.o src/ciphers/skipjack.o src/ciphers/twofish/twofish.o src/ciphers/xtea.o \
-src/encauth/ccm/ccm_add_aad.o src/encauth/ccm/ccm_add_nonce.o src/encauth/ccm/ccm_done.o \
-src/encauth/ccm/ccm_init.o src/encauth/ccm/ccm_memory.o src/encauth/ccm/ccm_process.o \
-src/encauth/ccm/ccm_reset.o src/encauth/ccm/ccm_test.o \
+src/ciphers/serpent.o src/ciphers/skipjack.o src/ciphers/tea.o src/ciphers/twofish/twofish.o \
+src/ciphers/xtea.o src/encauth/ccm/ccm_add_aad.o src/encauth/ccm/ccm_add_nonce.o \
+src/encauth/ccm/ccm_done.o src/encauth/ccm/ccm_init.o src/encauth/ccm/ccm_memory.o \
+src/encauth/ccm/ccm_process.o src/encauth/ccm/ccm_reset.o src/encauth/ccm/ccm_test.o \
 src/encauth/chachapoly/chacha20poly1305_add_aad.o src/encauth/chachapoly/chacha20poly1305_decrypt.o \
 src/encauth/chachapoly/chacha20poly1305_done.o src/encauth/chachapoly/chacha20poly1305_encrypt.o \
 src/encauth/chachapoly/chacha20poly1305_init.o src/encauth/chachapoly/chacha20poly1305_memory.o \

+ 4 - 4
makefile_include.mk

@@ -210,10 +210,10 @@ OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src
 src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/idea.o src/ciphers/kasumi.o \
 src/ciphers/khazad.o src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o \
 src/ciphers/rc5.o src/ciphers/rc6.o src/ciphers/safer/safer.o src/ciphers/safer/saferp.o \
-src/ciphers/serpent.o src/ciphers/skipjack.o src/ciphers/twofish/twofish.o src/ciphers/xtea.o \
-src/encauth/ccm/ccm_add_aad.o src/encauth/ccm/ccm_add_nonce.o src/encauth/ccm/ccm_done.o \
-src/encauth/ccm/ccm_init.o src/encauth/ccm/ccm_memory.o src/encauth/ccm/ccm_process.o \
-src/encauth/ccm/ccm_reset.o src/encauth/ccm/ccm_test.o \
+src/ciphers/serpent.o src/ciphers/skipjack.o src/ciphers/tea.o src/ciphers/twofish/twofish.o \
+src/ciphers/xtea.o src/encauth/ccm/ccm_add_aad.o src/encauth/ccm/ccm_add_nonce.o \
+src/encauth/ccm/ccm_done.o src/encauth/ccm/ccm_init.o src/encauth/ccm/ccm_memory.o \
+src/encauth/ccm/ccm_process.o src/encauth/ccm/ccm_reset.o src/encauth/ccm/ccm_test.o \
 src/encauth/chachapoly/chacha20poly1305_add_aad.o src/encauth/chachapoly/chacha20poly1305_decrypt.o \
 src/encauth/chachapoly/chacha20poly1305_done.o src/encauth/chachapoly/chacha20poly1305_encrypt.o \
 src/encauth/chachapoly/chacha20poly1305_init.o src/encauth/chachapoly/chacha20poly1305_memory.o \

+ 54 - 0
notes/cipher_tv.txt

@@ -2549,3 +2549,57 @@ Key Size: 32 bytes
 49: 80DEC7F355AEA1BCCD1F8209C3FE9E16
 
 
+Cipher: tea
+Key Size: 16 bytes
+ 0: 07D3CA2209D99A34
+ 1: 8AA2AB0843657382
+ 2: 231B235F7895BDA1
+ 3: 51CFB710B6CA50FD
+ 4: BC14673856317504
+ 5: 5BBE5F3F0897B3EF
+ 6: ABAAD961EAEE4908
+ 7: CFFD532347EB7D6B
+ 8: 0A677D4419B1F8CE
+ 9: E7D3055744921384
+10: 1458509E9D9AAE6D
+11: 038D0CB56FFD996B
+12: 2B36B73D385D3DF0
+13: 3DBC5982A528B9AA
+14: D6C7E606AF90CA7F
+15: 9CE6BBCC39AF11C3
+16: 591F6776C4B59FF3
+17: D39322630621C580
+18: DE2D2D98D1526D89
+19: B101FC38A8F915D6
+20: A2695E46228277FB
+21: CF8B6A0B1B1CEE21
+22: 29990F0FFBC40861
+23: 0F765791933BC0F9
+24: F94736075FDF68D5
+25: 2B29EBBEFA233845
+26: 6801BACE0B6AD59D
+27: 28DEC844CB3BC864
+28: 066B6AF32EC592E0
+29: E9FB041FEC4B2A9B
+30: D84C73A0A8373FAD
+31: 2C9E423F3762E688
+32: F6BAFB7A20F8FD06
+33: 3B0C18B126C1734F
+34: 9CD0A5DA38FB3FE6
+35: EBD38074D2039A4F
+36: 12F8007B2B2552BF
+37: E3A8D7EB6F20CD15
+38: 48AAEC5AE87A7AB6
+39: 05DF67BD335B67D3
+40: 8ECF370F9B397A6D
+41: E771760027A021EC
+42: 8B16418D1D18EBED
+43: 252904E3E9A91E88
+44: D7C870C14BEB0DAF
+45: 8C70C0A5786A3999
+46: 579D639AEBE8F8DF
+47: 0CA3D87B954DC6DF
+48: 3A24AD0D9A6C22B7
+49: D38FB50ACB2958CD
+
+

+ 19 - 0
notes/eax_tv.txt

@@ -621,3 +621,22 @@ EAX-serpent (16 byte key)
  31: EFD3F06A589F09A08D00A70F2235D64E54ED7E213F4D39191586087AC20833, 9035327451DBC7F9E9A49FF83B704C97
  32: 1DFDE8719F4FC7C235A1BB9862E1E6E132EC0C77EFEC71FD7E48C6B000C14291, 0CD8517E1B79FCA166F9D7CA1FB6336F
 
+EAX-tea (16 byte key)
+  0: , 581EF8A02372869F
+  1: FB, FB90C7378F6DBE3C
+  2: EC00, A19AB4ED51B2F2D5
+  3: 551BF7, 73E49811E90FDEC0
+  4: F9EA225A, CE609251E8693701
+  5: CDD0AEFEB0, 14E611D307EA66FD
+  6: 71C2847F58B5, 5CDF647518362E7B
+  7: 42409A216C573F, DE90E9CBF340587C
+  8: 4E66670E50D12994, A9C361739623DA73
+  9: 30208A8AABA72C07C5, B85CCFACD565CAC9
+ 10: EB24F57D350908B19AA1, A2BB5B52ADDCCD5D
+ 11: A30D1E71047FA930BB4FFB, 9F6088572C52A66F
+ 12: 9BCEFFABDC81E5003A05CD43, 4DA2ACF4FB189F52
+ 13: F3ADF893A855DA761BEA526AB4, 5FEE2D491403361D
+ 14: DB8E2662E8339B64D92B849E7DFB, 2EB5E802E63D80B7
+ 15: 5E0EF25BF8AB11A0D8E8E4C68BFFFA, 4B3E3136466D7B83
+ 16: A2B4256701C9E3AFF612B0E9614C510E, 1EB5503868796FDF
+

+ 19 - 0
notes/ocb_tv.txt

@@ -621,3 +621,22 @@ OCB-serpent (16 byte key)
  31: 77E2B65956B52BD90E90081F389BBFC8D4550FBCC74B6469C5CE98FC093A0F, C43272FD03A35AE4D9AF467CD7811F1D
  32: 77E116BE37F8153D717F3F19DEFD045C2E8CAC499295B9EE6A95A3509D4CBC47, A0406E2C09C510AB5A9E5A5B20B0C306
 
+OCB-tea (16 byte key)
+  0: , E1389796E71A9964
+  1: 52, 9AD765743EEF7E6C
+  2: 8FB4, C3AD7B2AA8BF6FDB
+  3: 4998DB, 3BB882FD3008226A
+  4: 5EAE4FBC, 09B37C919FD239CA
+  5: A7C3303005, 3F617FD1CC528C81
+  6: 3A325C2AC305, E2AC383FC0F167EF
+  7: E392792697A39C, 215D2FFF2921BEAC
+  8: 4E202347147693D7, B716880A27AF4DA4
+  9: DCA7B8360C9AC81FFB, 0BC016ADCF52508F
+ 10: 695967EBF5FCF3517499, 6C24E93417356D9B
+ 11: 248C5246F4C1DD0586BE74, 5ED892B4576C3028
+ 12: DEBAE87E44D2121D127837E8, 50146ACA34F44650
+ 13: 7C3DF8DEA0130C0C531E41C20A, E5CAB16B8EE6FD91
+ 14: F3E1FF2655AC34ED9E455788CBCB, 3EAF740FDC652506
+ 15: FA19BF16C8F2AEDA0608C3F9833352, 92380ECC4F20FA1A
+ 16: 469E76EEBAB8C2A1DC0AD4DD53584D0F, BDB10B835DF8623A
+

+ 19 - 0
notes/omac_tv.txt

@@ -621,3 +621,22 @@ OMAC-serpent (16 byte key)
  31: C7E18CC108DF3FF1E3A024A1B0B928E0
  32: 6E458187EC664A776005EA140154ACBF
 
+OMAC-tea (16 byte key)
+  0: 60897729F54131CF
+  1: 3E1CAB200AA5552F
+  2: 47A0EAF7FFE01BB0
+  3: 1447F1EC98212470
+  4: A58559E0BF9F9445
+  5: 3099C9A028D58D12
+  6: E5ADDD59BFD0495F
+  7: 3EA329EE687F8A25
+  8: 149685934D9CCAD1
+  9: 3130967CE43B22D5
+ 10: 2842C1C36B15E6DC
+ 11: 59A2E900143BE9C3
+ 12: 1211C81F2888AD0C
+ 13: 45DDA7DED8403233
+ 14: 2694A22BDEC4E7E5
+ 15: A3227929FA1CBBC7
+ 16: 59638CE1C63C7776
+

+ 19 - 0
notes/pmac_tv.txt

@@ -621,3 +621,22 @@ PMAC-serpent (16 byte key)
  31: 11F399978DB69A7957F2DF1A44206841
  32: D6C0DE7EEB98DA9EB0F800D2734B100A
 
+PMAC-tea (16 byte key)
+  0: 1B62CCC832F7C9AE
+  1: A1839B62B3DEE7CE
+  2: 0E1ADB184E1292EB
+  3: 595860B6F905D832
+  4: 202A473F69C85E8E
+  5: 66E459169829D505
+  6: AB602CB86A0F7AAA
+  7: A06636338D7DC52E
+  8: 254DEC5F2600B5AE
+  9: E818966534DBB92B
+ 10: 94E47556B975726D
+ 11: 5A0E20AFE5620715
+ 12: 5A7A930E9E3AA535
+ 13: F4D22501B3E52121
+ 14: 998261FF1B92CEC2
+ 15: 97A766D863814EDB
+ 16: 6FACD2074DEE6AC6
+

+ 219 - 0
src/ciphers/tea.c

@@ -0,0 +1,219 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ */
+
+/**
+  @file tea.c
+  Implementation of TEA, Steffen Jaeckel
+*/
+#include "tomcrypt_private.h"
+
+#ifdef LTC_TEA
+
+const struct ltc_cipher_descriptor tea_desc =
+{
+    "tea",
+    26,
+    16, 16, 8, 32,
+    &tea_setup,
+    &tea_ecb_encrypt,
+    &tea_ecb_decrypt,
+    &tea_test,
+    &tea_done,
+    &tea_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+#define DELTA 0x9E3779B9uL
+#define SUM 0xC6EF3720uL
+
+int tea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+{
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   /* check arguments */
+   if (keylen != 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+
+   if (num_rounds != 0 && num_rounds != 32) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
+   /* load key */
+   LOAD32H(skey->tea.k[0], key+0);
+   LOAD32H(skey->tea.k[1], key+4);
+   LOAD32H(skey->tea.k[2], key+8);
+   LOAD32H(skey->tea.k[3], key+12);
+
+   return CRYPT_OK;
+}
+
+/**
+  Encrypts a block of text with TEA
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+  @return CRYPT_OK if successful
+*/
+int tea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+{
+   ulong32 y, z, sum = 0;
+   const ulong32 delta = DELTA;
+   int r;
+
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   LOAD32H(y, &pt[0]);
+   LOAD32H(z, &pt[4]);
+   for (r = 0; r < 32; r += 4) {
+      sum += delta;
+      y += ((z<<4) + skey->tea.k[0]) ^ (z + sum) ^ ((z>>5) + skey->tea.k[1]);
+      z += ((y<<4) + skey->tea.k[2]) ^ (y + sum) ^ ((y>>5) + skey->tea.k[3]);
+   }
+   STORE32H(y, &ct[0]);
+   STORE32H(z, &ct[4]);
+   return CRYPT_OK;
+}
+
+/**
+  Decrypts a block of text with TEA
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled
+  @return CRYPT_OK if successful
+*/
+int tea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+{
+   ulong32 v0, v1, sum = SUM;
+   const ulong32 delta = DELTA;
+   int r;
+
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   LOAD32H(v0, &ct[0]);
+   LOAD32H(v1, &ct[4]);
+
+   for (r = 0; r < 32; r++) {
+      v1 -= ((v0 << 4) + skey->tea.k[2]) ^ (v0 + sum) ^ ((v0 >> 5) + skey->tea.k[3]);
+      v0 -= ((v1 << 4) + skey->tea.k[0]) ^ (v1 + sum) ^ ((v1 >> 5) + skey->tea.k[1]);
+      sum -= delta;
+   }
+
+   STORE32H(v0, &pt[0]);
+   STORE32H(v1, &pt[4]);
+   return CRYPT_OK;
+}
+
+/**
+  Performs a self-test of the TEA block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
+int tea_test(void)
+{
+ #ifndef LTC_TEST
+    return CRYPT_NOP;
+ #else
+    static const struct {
+        const char *key, *pt, *ct;
+    } tests[] = {
+       {
+         "00000000000000000000000000000000",
+         "0000000000000000",
+         "41ea3a0a94baa940"
+       }, {
+         "32a1e65408b63bb9214105744ec5d2e2",
+         "5ada1d89a9c3801a",
+         "dd46249e28aa0b4b"
+       }, {
+         "60388adadf70a1f5d9cb4e097d2c6c57",
+         "7a6adb4d69c53e0f",
+         "44b71215cf25368a"
+       }, {
+         "4368d2249bd0321eb7c56d5b63a1bfac",
+         "5a5d7ca2e186c41a",
+         "91f56dff7281794f"
+       }, {
+         "5c60bff27072d01c4513c5eb8f3a38ab",
+         "80d9c4adcf899635",
+         "2bb0f1b3c023ed11"
+       }
+    };
+   unsigned char ptct[2][8];
+   unsigned char tmp[2][8];
+   unsigned char key[16];
+   unsigned long l;
+   symmetric_key skey;
+   size_t i;
+   int err, y;
+   for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
+       zeromem(&skey, sizeof(skey));
+
+       l = sizeof(key);
+       if ((err = base16_decode(tests[i].key, strlen(tests[i].key), key, &l)) != CRYPT) return err;
+       l = sizeof(ptct[0]);
+       if ((err = base16_decode(tests[i].pt, strlen(tests[i].pt), ptct[0], &l)) != CRYPT) return err;
+       l = sizeof(ptct[1]);
+       if ((err = base16_decode(tests[i].ct, strlen(tests[i].ct), ptct[1], &l)) != CRYPT) return err;
+
+       if ((err = tea_setup(key, 16, 0, &skey)) != CRYPT_OK)  {
+          return err;
+       }
+       tea_ecb_encrypt(ptct[0], tmp[0], &skey);
+       tea_ecb_decrypt(tmp[0], tmp[1], &skey);
+
+       if (compare_testvector(tmp[0], 8, ptct[0], 8, "TEA Encrypt", i) != 0 ||
+             compare_testvector(tmp[1], 8, ptct[1], 8, "TEA Decrypt", i) != 0) {
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+      /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
+      for (y = 0; y < 8; y++) tmp[0][y] = 0;
+      for (y = 0; y < 1000; y++) tea_ecb_encrypt(tmp[0], tmp[0], &skey);
+      for (y = 0; y < 1000; y++) tea_ecb_decrypt(tmp[0], tmp[0], &skey);
+      for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
+   } /* for */
+
+   return CRYPT_OK;
+ #endif
+}
+
+/** Terminate the context
+   @param skey    The scheduled key
+*/
+void tea_done(symmetric_key *skey)
+{
+  LTC_UNUSED_PARAM(skey);
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int tea_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+   *keysize = 16;
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */

+ 1 - 1
src/ciphers/xtea.c

@@ -9,7 +9,7 @@
 
 /**
   @file xtea.c
-  Implementation of LTC_XTEA, Tom St Denis
+  Implementation of eXtended TEA, Tom St Denis
 */
 #include "tomcrypt_private.h"
 

+ 19 - 0
src/headers/tomcrypt_cipher.h

@@ -171,6 +171,12 @@ struct serpent_key {
 };
 #endif
 
+#ifdef LTC_TEA
+struct tea_key {
+   ulong32 k[4];
+};
+#endif
+
 typedef union Symmetric_key {
 #ifdef LTC_DES
    struct des_key des;
@@ -235,6 +241,9 @@ typedef union Symmetric_key {
 #endif
 #ifdef LTC_SERPENT
    struct serpent_key  serpent;
+#endif
+#ifdef LTC_TEA
+   struct tea_key      tea;
 #endif
    void   *data;
 } symmetric_key;
@@ -859,6 +868,16 @@ int serpent_keysize(int *keysize);
 extern const struct ltc_cipher_descriptor serpent_desc;
 #endif
 
+#ifdef LTC_TEA
+int tea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+int tea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
+int tea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
+int tea_test(void);
+void tea_done(symmetric_key *skey);
+int tea_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor tea_desc;
+#endif
+
 #ifdef LTC_ECB_MODE
 int ecb_start(int cipher, const unsigned char *key,
               int keylen, int num_rounds, symmetric_ECB *ecb);

+ 1 - 0
src/headers/tomcrypt_custom.h

@@ -207,6 +207,7 @@
 #define LTC_CAMELLIA
 #define LTC_IDEA
 #define LTC_SERPENT
+#define LTC_TEA
 
 /* stream ciphers */
 #define LTC_CHACHA

+ 3 - 0
src/misc/crypt/crypt.c

@@ -127,6 +127,9 @@ const char *crypt_build_settings =
 #endif
 #if defined(LTC_SERPENT)
    "   Serpent\n"
+#endif
+#if defined(LTC_TEA)
+   "   TEA\n"
 #endif
    "Stream ciphers built-in:\n"
 #if defined(LTC_CHACHA)

+ 3 - 0
src/misc/crypt/crypt_register_all_ciphers.c

@@ -97,6 +97,9 @@ int register_all_ciphers(void)
 #endif
 #ifdef LTC_SERPENT
    REGISTER_CIPHER(&serpent_desc);
+#endif
+#ifdef LTC_TEA
+   REGISTER_CIPHER(&tea_desc);
 #endif
    return CRYPT_OK;
 }