Fix endianness issues.
authorAndrey Rys <rys@lynxlynx.ru>
Fri, 15 Mar 2019 10:15:50 +0000 (17:15 +0700)
committerAndrey Rys <rys@lynxlynx.ru>
Fri, 15 Mar 2019 10:15:50 +0000 (17:15 +0700)
tfctrapi: do not post convert, do preconversion of both arguments instead, then add.
tfe: remove endianness converters, caller must do conversion.

VERSION
tfcrypt.c
tfctrapi.c
tfe.c

diff --git a/VERSION b/VERSION
index 48082f72f087ce7e6fa75b9c41d7387daecd447b..b1bd38b62a0800a4f6a80c34e21c5acffae52c7e 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-12
+13
index 363e3c4825c8735dcae93c7e10cf338fbcb49056..4724c0fab024cf88ab10fa8492dfce05c0cbeb76 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -903,11 +903,12 @@ _xts2genkey:      if (xwrite(krfd, pblk, TF_FROM_BITS(TFC_KEY_BITS)) == NOSIZE) xerro
                if (!tweakf) skein(key+TF_FROM_BITS(TF_MAX_BITS)+TF_SIZE_UNIT, 2*TF_UNIT_BITS, NULL, key, TF_FROM_BITS(TFC_KEY_BITS));
                tf_key_tweak_compat(key);
        }
-       if (ctr_mode == TFC_MODE_STREAM) tfe_init_iv(&tfe, key, ctr);
        if (ctr_mode == TFC_MODE_ECB) goto _ctrskip2;
        tfc_data_to_words64(&iseek_blocks, sizeof(iseek_blocks));
        tf_ctr_set(ctr, &iseek_blocks, sizeof(iseek_blocks));
 
+       if (ctr_mode == TFC_MODE_STREAM) tfe_init_iv(&tfe, key, ctr);
+
        switch (counter_opt) {
                case TFC_CTR_SHOW:
                        switch (do_outfmt) {
index 2845b2dba0b820a7a87222810111a6944180d9ba..67ec44b714f37efcc78686f7f3857f41afa45c1d 100644 (file)
@@ -6,9 +6,12 @@ void tf_ctr_set(void *ctr, const void *sctr, size_t sctrsz)
        TF_UNIT_TYPE usctr[TF_NR_BLOCK_UNITS];
        TF_UNIT_TYPE *uctr = ctr;
 
+       data_to_words(uctr, TF_BLOCK_SIZE);
+
        memset(usctr, 0, TF_BLOCK_SIZE);
        memcpy(usctr, sctr, sctrsz > TF_BLOCK_SIZE ? TF_BLOCK_SIZE : sctrsz);
+       data_to_words(usctr, TF_BLOCK_SIZE);
+
        ctr_add(uctr, TF_NR_BLOCK_UNITS, usctr, TF_NR_BLOCK_UNITS);
-       data_to_words(uctr, TF_BLOCK_SIZE);
        memset(usctr, 0, TF_BLOCK_SIZE);
 }
diff --git a/tfe.c b/tfe.c
index 544bcc7bed097f853140bb3c1f78ff3d5a6be8ce..127d063cd26d71fe0f96055ae30839ed0a80d603 100644 (file)
--- a/tfe.c
+++ b/tfe.c
@@ -6,11 +6,7 @@ void tfe_init_iv(struct tfe_stream *tfe, const void *key, const void *iv)
 {
        memset(tfe, 0, sizeof(struct tfe_stream));
        memcpy(tfe->key, key, TF_KEY_SIZE);
-       data_to_words(tfe->key, TF_KEY_SIZE);
-       if (iv) {
-               memcpy(tfe->iv, iv, TF_BLOCK_SIZE);
-               data_to_words(tfe->iv, TF_BLOCK_SIZE);
-       }
+       if (iv) memcpy(tfe->iv, iv, TF_BLOCK_SIZE);
        tfe->carry_bytes = 0;
 }