X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_skein.c;h=e05927da18385375aa61ea314737b65e9f2890be;hb=ee5e048cace46d40dfb9fe450eb00f977c78ab12;hp=6c595e1bcd206339a44ad9c84682853ce642ac65;hpb=2da8baf01e863c80eccdeb5f428f16e1cf3a0473;p=tfcrypt.git diff --git a/tfc_skein.c b/tfc_skein.c index 6c595e1..e05927d 100644 --- a/tfc_skein.c +++ b/tfc_skein.c @@ -39,17 +39,7 @@ void skein(void *hash, size_t bits, const void *key, const void *data, size_t sz skein_final(hash, &sk); } -void tf_key_tweak_compat(void *key) -{ - TF_UNIT_TYPE *ukey = key, c = THREEFISH_CONST; - size_t x; - - for (x = 0; x < TF_NR_BLOCK_UNITS; x++) c ^= ukey[x]; - ukey[x] = c; - ukey[TF_TWEAK_WORD3] = ukey[TF_TWEAK_WORD1] ^ ukey[TF_TWEAK_WORD2]; -} - -tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize readto) +tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize offset, tfc_fsize readto) { static tfc_byte skblk[TFC_BLKSIZE]; @@ -62,9 +52,16 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize re if (ctr_mode == TFC_MODE_SKSUM) total_processed_src = total_processed_dst = delta_processed = 0; if (fd == -1) goto _fail; - if (fd > 2 && readto == NOFSIZE) { - readto = tfc_fdsize(fd); - if (readto == NOFSIZE) goto _fail; + if (fd > 2) { + if (readto == NOFSIZE) { + readto = tfc_fdsize(fd); + if (readto == NOFSIZE) goto _fail; + } + if (offset != 0 && offset != NOFSIZE) { + if (lseek(fd, (off_t)offset, SEEK_SET) == -1) { + if (ignore_seek_errors == NO) goto _fail; + } + } } if (key) skein_init_key(&sk, key, bits); @@ -78,7 +75,7 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize re lblock = lrem = blk_len_adj(readto, total, TFC_BLKSIZE); ldone = 0; if (error_action == TFC_ERRACT_SYNC) rdpos = tfc_fdgetpos(fd); -_again: lio = read(fd, pblk, lrem); +_again: lio = xread(fd, pblk, lrem); if (lio == 0) stop = YES; if (lio != NOSIZE) ldone += lio; else { @@ -197,8 +194,7 @@ _dothat: while (1) { memset(sksblk, 0, sizeof(sksblk)); - x = xfgets(sksblk, sizeof(sksblk), f); - if (x == 0) break; + if (xfgets(sksblk, sizeof(sksblk), f) != YES) break; s = d = sksblk; t = NULL; shash = fname = NULL; @@ -226,7 +222,7 @@ _dothat: } if (status_timer) setup_next_alarm(status_timer); - if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, maxlen) != YES) { + if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, iseek, maxlen) != YES) { xerror(YES, NO, YES, "%s", fname); exitcode = 1; continue; @@ -278,7 +274,7 @@ _dothat: } _dohash: if (status_timer) setup_next_alarm(status_timer); - if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, maxlen) != YES) { + if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, iseek, maxlen) != YES) { xerror(YES, NO, YES, "%s", fargv[x]); exitcode = 1; continue; @@ -289,7 +285,7 @@ _dohash: if (status_timer) setup_next_alarm(status_timer); for (y = 0; y < sksum_turns; y++) skein(hash, bits, mackey_opt ? mackey : NULL, hash, TF_FROM_BITS(bits)); } if (do_outfmt == TFC_OUTFMT_B64) tfc_printbase64(stdout, hash, TF_FROM_BITS(bits), 0); - else if (do_outfmt == TFC_OUTFMT_RAW) write(1, hash, TF_FROM_BITS(bits)); + else if (do_outfmt == TFC_OUTFMT_RAW) xwrite(1, hash, TF_FROM_BITS(bits)); else mhexdump(hash, TF_FROM_BITS(bits), TF_FROM_BITS(bits), 0); if (do_outfmt != TFC_OUTFMT_RAW) { if (quiet == NO || xx > 1) tfc_say("\t%s", fargv[x] ? fargv[x] : "-");