5 void tfe_init_iv(struct tfe_stream *tfe, const void *key, const void *iv)
7 memset(tfe, 0, sizeof(struct tfe_stream));
8 memcpy(tfe->key, key, TF_KEY_SIZE);
9 if (iv) memcpy(tfe->iv, iv, TF_BLOCK_SIZE);
13 void tfe_init(struct tfe_stream *tfe, const void *key)
15 tfe_init_iv(tfe, key, NULL);
18 void tfe_emit(void *dst, size_t szdst, struct tfe_stream *tfe)
20 TF_BYTE_TYPE *udst = dst;
21 size_t sz = szdst, trem;
23 if (!dst && szdst == 0) {
24 memset(tfe, 0, sizeof(struct tfe_stream));
29 trem = TF_BLOCK_SIZE-tfe->tidx;
32 memcpy(udst, &tfe->tmp[tfe->tidx], szdst);
34 if (tfe->tidx >= TF_BLOCK_SIZE) tfe->tidx = 0;
38 memcpy(udst, &tfe->tmp[tfe->tidx], trem);
44 if (sz >= TF_BLOCK_SIZE) {
46 tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
47 memcpy(udst, tfe->iv, TF_BLOCK_SIZE);
48 data_to_words(udst, TF_BLOCK_SIZE);
49 udst += TF_BLOCK_SIZE;
50 } while ((sz -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
54 tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
55 memcpy(tfe->tmp, tfe->iv, TF_BLOCK_SIZE);
56 data_to_words(tfe->tmp, TF_BLOCK_SIZE);
57 memcpy(udst, tfe->tmp, sz);