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;
23 if (!dst && szdst == 0) {
24 memset(tfe, 0, sizeof(struct tfe_stream));
28 if (tfe->carry_bytes > 0) {
29 if (tfe->carry_bytes > szdst) {
30 memcpy(udst, tfe->carry_block, szdst);
31 memmove(tfe->carry_block, tfe->carry_block+szdst, tfe->carry_bytes-szdst);
32 tfe->carry_bytes -= szdst;
36 memcpy(udst, tfe->carry_block, tfe->carry_bytes);
37 udst += tfe->carry_bytes;
38 sz -= tfe->carry_bytes;
42 if (sz >= TF_BLOCK_SIZE) {
44 tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
45 memcpy(udst, tfe->iv, TF_BLOCK_SIZE);
46 data_to_words(udst, TF_BLOCK_SIZE);
47 udst += TF_BLOCK_SIZE;
48 } while ((sz -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
52 TF_UNIT_TYPE t[TF_NR_BLOCK_UNITS];
54 tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
55 memcpy(t, tfe->iv, TF_BLOCK_SIZE);
56 data_to_words(t, TF_BLOCK_SIZE);
58 memset(t, 0, TF_BLOCK_SIZE);
59 udst = (TF_BYTE_TYPE *)tfe->iv;
60 tfe->carry_bytes = TF_BLOCK_SIZE-sz;
61 memcpy(tfe->carry_block, udst+sz, tfe->carry_bytes);