X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_skein.c;h=0917819e241196b7f9459e2dbbb4dea8198306e3;hb=92b6bb91a5be9fc1b4d300f99b239cb8e3a6398d;hp=6c595e1bcd206339a44ad9c84682853ce642ac65;hpb=2da8baf01e863c80eccdeb5f428f16e1cf3a0473;p=tfcrypt.git diff --git a/tfc_skein.c b/tfc_skein.c index 6c595e1..0917819 100644 --- a/tfc_skein.c +++ b/tfc_skein.c @@ -2,7 +2,7 @@ * tfcrypt -- high security Threefish encryption tool. * * tfcrypt is copyrighted: - * Copyright (C) 2012-2018 Andrey Rys. All rights reserved. + * Copyright (C) 2012-2019 Andrey Rys. All rights reserved. * * tfcrypt is licensed to you under the terms of std. MIT/X11 license: * @@ -29,6 +29,12 @@ #include "tfcrypt.h" #include "tfcore.h" +static void exit_sigterm_skein(int signal) +{ + if (xexit_no_nl == YES) xexit_no_nl = NO; + exit_sigterm(signal); +} + void skein(void *hash, size_t bits, const void *key, const void *data, size_t szdata) { struct skein sk; @@ -39,17 +45,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]; @@ -57,29 +53,35 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize re tfc_byte *pblk; size_t ldone, lblock, lrem, lio; tfc_fsize total = 0; - tfc_yesno stop; 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); else skein_init(&sk, bits); errno = 0; - stop = NO; + do_stop = NO; while (1) { - if (stop) break; + if (do_stop) break; pblk = skblk; 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); - if (lio == 0) stop = YES; +_again: lio = xread(fd, pblk, lrem); + if (lio == 0) do_stop = YES; if (lio != NOSIZE) ldone += lio; else { if (errno != EIO && catch_all_errors != YES) goto _fail; @@ -115,7 +117,10 @@ _again: lio = read(fd, pblk, lrem); skein_final(hash, &sk); if (ctr_mode == TFC_MODE_SKSUM) { - if (verbose || status_timer) print_crypt_status(-1); + if (verbose || status_timer) { + print_crypt_status(-1); + tfc_esay("\n"); + } total_processed_src = total_processed_dst = delta_processed = 0; } memset(skblk, 0, TFC_BLKSIZE); @@ -136,6 +141,8 @@ void do_sksum(char *spec, char **fargv) int x = 0, xx; size_t bits; + xexit_no_nl = YES; + if (macbits < TF_MAX_BITS) { bits = macbits; goto _dothat; @@ -173,15 +180,16 @@ _dothat: sigact.sa_flags = SA_RESTART; sigact.sa_handler = print_crypt_status; sigaction(SIGUSR1, &sigact, NULL); - sigaction(SIGTSTP, &sigact, NULL); sigaction(SIGALRM, &sigact, NULL); sigact.sa_handler = change_status_width; sigaction(SIGQUIT, &sigact, NULL); sigact.sa_handler = change_status_timer; sigaction(SIGUSR2, &sigact, NULL); - sigact.sa_handler = exit_sigterm; + sigact.sa_handler = exit_sigterm_skein; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); + sigact.sa_handler = handle_sigtstp; + sigaction(SIGTSTP, &sigact, NULL); memset(&sigact, 0, sizeof(struct sigaction)); tfc_getcurtime(&delta_time); @@ -197,8 +205,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; @@ -225,8 +232,8 @@ _dothat: continue; } - if (status_timer) setup_next_alarm(status_timer); - if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, maxlen) != YES) { + if (status_timer) setup_next_alarm(status_timer > 1000000 ? 1000000 : status_timer); + if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, iseek, maxlen) != YES) { xerror(YES, NO, YES, "%s", fname); exitcode = 1; continue; @@ -255,7 +262,7 @@ _dothat: fclose(f); if (failed) { tfc_esay("%s: WARNING: %u of %u computed checksums did NOT match", - progname, failed, totaltested); + tfc_format_pid(progname), failed, totaltested); exitcode = 1; } xexit(exitcode); @@ -277,8 +284,8 @@ _dothat: continue; } -_dohash: if (status_timer) setup_next_alarm(status_timer); - if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, maxlen) != YES) { +_dohash: if (status_timer) setup_next_alarm(status_timer > 1000000 ? 1000000 : status_timer); + if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, iseek, maxlen) != YES) { xerror(YES, NO, YES, "%s", fargv[x]); exitcode = 1; continue; @@ -289,7 +296,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] : "-");