4 void tf_ctr_crypt(const void *key, void *ctr, 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 TF_UNIT_TYPE *uctr = ctr;
10 const TF_UNIT_TYPE *ukey = key;
13 if (sl >= TF_BLOCK_SIZE) {
15 memcpy(x, uin, TF_BLOCK_SIZE);
17 data_to_words(x, TF_BLOCK_SIZE);
19 ctr_inc(uctr, TF_NR_BLOCK_UNITS);
20 tf_encrypt_rawblk(y, uctr, ukey);
21 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
23 data_to_words(y, TF_BLOCK_SIZE);
24 memcpy(uout, y, TF_BLOCK_SIZE);
25 uout += TF_BLOCK_SIZE;
26 } while ((sl -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
30 memset(x, 0, TF_BLOCK_SIZE);
32 data_to_words(x, TF_BLOCK_SIZE);
34 ctr_inc(uctr, TF_NR_BLOCK_UNITS);
35 tf_encrypt_rawblk(y, uctr, ukey);
36 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
38 data_to_words(y, TF_BLOCK_SIZE);
42 memset(x, 0, TF_BLOCK_SIZE);
43 memset(y, 0, TF_BLOCK_SIZE);