tfe: fix endianness with blocks smaller than TF_BLOCK_SIZE.
authorAndrey Rys <rys@lynxlynx.ru>
Sun, 18 Aug 2019 10:47:28 +0000 (12:47 +0200)
committerAndrey Rys <rys@lynxlynx.ru>
Sun, 18 Aug 2019 10:49:05 +0000 (12:49 +0200)
VERSION
tfe.c

diff --git a/VERSION b/VERSION
index f5c89552bd3e62bfce023a230e90d141f7a46b2f..bb95160cb6e07358f54a28a208ae41e69889c97b 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-32
+33
diff --git a/tfe.c b/tfe.c
index 127d063cd26d71fe0f96055ae30839ed0a80d603..eea50d36e46c45cc81b8e5ce0ac7be4bc8164c10 100644 (file)
--- a/tfe.c
+++ b/tfe.c
@@ -49,9 +49,13 @@ void tfe_emit(void *dst, size_t szdst, struct tfe_stream *tfe)
        }
 
        if (sz) {
+               TF_UNIT_TYPE t[TF_NR_BLOCK_UNITS];
+
                tf_encrypt_rawblk(tfe->iv, tfe->iv, tfe->key);
-               memcpy(udst, tfe->iv, sz);
-               data_to_words(udst, TF_BLOCK_SIZE);
+               memcpy(t, tfe->iv, TF_BLOCK_SIZE);
+               data_to_words(t, TF_BLOCK_SIZE);
+               memcpy(udst, t, sz);
+               memset(t, 0, TF_BLOCK_SIZE);
                udst = (TF_BYTE_TYPE *)tfe->iv;
                tfe->carry_bytes = TF_BLOCK_SIZE-sz;
                memcpy(tfe->carry_block, udst+sz, tfe->carry_bytes);