From: Andrey Rys Date: Fri, 15 Mar 2019 10:15:50 +0000 (+0700) Subject: Fix endianness issues. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=e0d3bb48cd0cd079f9d1bd5555a52f450db452ac;p=tfcrypt.git Fix endianness issues. tfctrapi: do not post convert, do preconversion of both arguments instead, then add. tfe: remove endianness converters, caller must do conversion. --- diff --git a/VERSION b/VERSION index 48082f7..b1bd38b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -12 +13 diff --git a/tfcrypt.c b/tfcrypt.c index 363e3c4..4724c0f 100644 --- 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) { diff --git a/tfctrapi.c b/tfctrapi.c index 2845b2d..67ec44b 100644 --- a/tfctrapi.c +++ b/tfctrapi.c @@ -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 544bcc7..127d063 100644 --- 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; }