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 data_to_words(tfe->key, TF_KEY_SIZE);
11 memcpy(tfe->iv, iv, TF_BLOCK_SIZE);
12 data_to_words(tfe->iv, TF_BLOCK_SIZE);
17 void tfe_init(struct tfe_stream *tfe, const void *key)
19 tfe_init_iv(tfe, key, NULL);
22 void tfe_emit(void *dst, size_t szdst, struct tfe_stream *tfe)
24 TF_BYTE_TYPE *udst = dst;
27 if (!dst && szdst == 0) {
28 memset(tfe, 0, sizeof(struct tfe_stream));
32 if (tfe->carry_bytes > 0) {
33 if (tfe->carry_bytes > szdst) {
34 memcpy(udst, tfe->carry_block, szdst);
35 memmove(tfe->carry_block, tfe->carry_block+szdst, tfe->carry_bytes-szdst);
36 tfe->carry_bytes -= szdst;
40 memcpy(udst, tfe->carry_block, tfe->carry_bytes);
41 udst += tfe->carry_bytes;
42 sz -= tfe->carry_bytes;
46 if (sz >= TF_BLOCK_SIZE) {
48 tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
49 memcpy(udst, tfe->iv, TF_BLOCK_SIZE);
50 data_to_words(udst, TF_BLOCK_SIZE);
51 udst += TF_BLOCK_SIZE;
52 } while ((sz -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
56 tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
57 memcpy(udst, tfe->iv, sz);
58 data_to_words(udst, 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);