4 void tf_pcbc_encrypt(const void *key, void *iv, void *out, const void *in, size_t sz)
6 const TF_BYTE_TYPE *uin = (const TF_BYTE_TYPE *)in;
7 TF_BYTE_TYPE *uout = (TF_BYTE_TYPE *)out;
8 TF_UNIT_TYPE x[TF_NR_BLOCK_UNITS], y[TF_NR_BLOCK_UNITS];
9 TF_UNIT_TYPE *uiv = (TF_UNIT_TYPE *)iv;
10 const TF_UNIT_TYPE *ukey = (const TF_UNIT_TYPE *)key;
13 if (sl >= TF_BLOCK_SIZE) {
15 memcpy(x, uin, TF_BLOCK_SIZE);
17 data_to_words(x, TF_BLOCK_SIZE);
19 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] = x[i] ^ uiv[i];
20 tf_encrypt_rawblk(y, y, ukey);
21 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) uiv[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(uiv, TF_NR_BLOCK_UNITS);
35 tf_encrypt_rawblk(y, uiv, 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);
46 void tf_pcbc_decrypt(const void *key, void *iv, void *out, const void *in, size_t sz)
48 const TF_BYTE_TYPE *uin = (const TF_BYTE_TYPE *)in;
49 TF_BYTE_TYPE *uout = (TF_BYTE_TYPE *)out;
50 TF_UNIT_TYPE x[TF_NR_BLOCK_UNITS], y[TF_NR_BLOCK_UNITS];
51 TF_UNIT_TYPE *uiv = (TF_UNIT_TYPE *)iv;
52 const TF_UNIT_TYPE *ukey = (const TF_UNIT_TYPE *)key;
55 if (sl >= TF_BLOCK_SIZE) {
57 memcpy(x, uin, TF_BLOCK_SIZE);
59 data_to_words(x, TF_BLOCK_SIZE);
61 tf_decrypt_rawblk(y, x, ukey);
62 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= uiv[i];
63 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) uiv[i] = y[i] ^ x[i];
65 data_to_words(y, TF_BLOCK_SIZE);
66 memcpy(uout, y, TF_BLOCK_SIZE);
67 uout += TF_BLOCK_SIZE;
68 } while ((sl -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
72 memset(x, 0, TF_BLOCK_SIZE);
74 data_to_words(x, TF_BLOCK_SIZE);
76 ctr_inc(uiv, TF_NR_BLOCK_UNITS);
77 tf_encrypt_rawblk(y, uiv, ukey);
78 for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
80 data_to_words(y, TF_BLOCK_SIZE);
84 memset(x, 0, TF_BLOCK_SIZE);
85 memset(y, 0, TF_BLOCK_SIZE);