4 void tf_ecb_encrypt(const void *key, void *out, const void *in, size_t sz)
6 const TF_BYTE_TYPE *uin = in;
7 TF_BYTE_TYPE *uout = out;
8 TF_UNIT_TYPE x[TF_NR_BLOCK_UNITS], y[TF_NR_BLOCK_UNITS];
9 const TF_UNIT_TYPE *ukey = key;
12 if (sl >= TF_BLOCK_SIZE) {
14 memcpy(x, uin, TF_BLOCK_SIZE);
16 data_to_words(x, TF_BLOCK_SIZE);
18 tf_encrypt_rawblk(y, x, ukey);
20 data_to_words(y, TF_BLOCK_SIZE);
21 memcpy(uout, y, TF_BLOCK_SIZE);
22 uout += TF_BLOCK_SIZE;
23 } while ((sl -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
27 memset(x, 0, TF_BLOCK_SIZE);
29 data_to_words(x, TF_BLOCK_SIZE);
31 memset(y, 0, TF_BLOCK_SIZE);
32 tf_encrypt_rawblk(y, y, ukey);
33 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
35 data_to_words(y, TF_BLOCK_SIZE);
39 memset(x, 0, TF_BLOCK_SIZE);
40 memset(y, 0, TF_BLOCK_SIZE);
43 void tf_ecb_decrypt(const void *key, void *out, const void *in, size_t sz)
45 const TF_BYTE_TYPE *uin = in;
46 TF_BYTE_TYPE *uout = out;
47 TF_UNIT_TYPE x[TF_NR_BLOCK_UNITS], y[TF_NR_BLOCK_UNITS];
48 const TF_UNIT_TYPE *ukey = key;
51 if (sl >= TF_BLOCK_SIZE) {
53 memcpy(x, uin, TF_BLOCK_SIZE);
55 data_to_words(x, TF_BLOCK_SIZE);
57 tf_decrypt_rawblk(y, x, ukey);
59 data_to_words(y, TF_BLOCK_SIZE);
60 memcpy(uout, y, TF_BLOCK_SIZE);
61 uout += TF_BLOCK_SIZE;
62 } while ((sl -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
66 memset(x, 0, TF_BLOCK_SIZE);
68 data_to_words(x, TF_BLOCK_SIZE);
70 memset(y, 0, TF_BLOCK_SIZE);
71 tf_decrypt_rawblk(y, y, ukey);
72 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
74 data_to_words(y, TF_BLOCK_SIZE);
78 memset(x, 0, TF_BLOCK_SIZE);
79 memset(y, 0, TF_BLOCK_SIZE);