X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_skein.c;h=a3685783d28333bf58aa5de9b1c32007e8081e9f;hb=HEAD;hp=5d457deac828513156db13ced328d11feb6ef9e7;hpb=630fb7d8dc740715cdc52114d736d64bf14f0798;p=tfcrypt.git diff --git a/tfc_skein.c b/tfc_skein.c index 5d457de..a368578 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,11 @@ #include "tfcrypt.h" #include "tfcore.h" +static void exit_sigterm_skein(int signal) +{ + exit_sigterm(signal); +} + void skein(void *hash, size_t bits, const void *key, const void *data, size_t szdata) { struct skein sk; @@ -39,16 +44,6 @@ 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 offset, tfc_fsize readto) { static tfc_byte skblk[TFC_BLKSIZE]; @@ -57,7 +52,6 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize of 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; @@ -78,15 +72,15 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize of 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 = xread(fd, pblk, lrem); - if (lio == 0) stop = YES; + if (lio == 0) do_stop = YES; if (lio != NOSIZE) ldone += lio; else { if (errno != EIO && catch_all_errors != YES) goto _fail; @@ -122,7 +116,10 @@ _again: lio = xread(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(TFC_SIGSTAT); + tfc_esay("\n"); + } total_processed_src = total_processed_dst = delta_processed = 0; } memset(skblk, 0, TFC_BLKSIZE); @@ -180,15 +177,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); @@ -204,8 +202,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,14 +222,14 @@ _dothat: s = strchr(shash, ' '); if (s && s[1] == ' ') *s = 0; - fd = open(fname, O_RDONLY | O_LARGEFILE); + fd = xxopen(YES, fname, O_RDONLY | O_LARGEFILE); if (fd == -1) { xerror(YES, NO, YES, "%s", fname); exitcode = 1; continue; } - if (status_timer) setup_next_alarm(status_timer); + 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; @@ -262,7 +259,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,14 +274,14 @@ _dothat: for (x = 0; fargv[x] && xx; x++) { if (!strcmp(fargv[x], "-")) fd = 0; - else fd = open(fargv[x], O_RDONLY | O_LARGEFILE); + else fd = xxopen(YES, fargv[x], O_RDONLY | O_LARGEFILE); if (fd == -1) { xerror(YES, NO, YES, "%s", fargv[x]); exitcode = 1; continue; } -_dohash: if (status_timer) setup_next_alarm(status_timer); +_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;