2 * tfcrypt -- high security Threefish encryption tool.
4 * tfcrypt is copyrighted:
5 * Copyright (C) 2012-2019 Andrey Rys. All rights reserved.
7 * tfcrypt is licensed to you under the terms of std. MIT/X11 license:
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 void exit_sigterm(int signal)
36 void print_crypt_status(int signal)
39 double seconds, human_totalproc_src, human_totalproc_dst, human_totalwrit_dst, human_wr_speed;
40 int src_scale_idx, dst_scale_idx, wri_scale_idx, wr_speed_scale;
41 const char *oper_mode, *inplace;
42 static tfc_yesno last;
44 if (last == YES) return;
45 if (signal == 0 || signal == -1) last = YES;
48 case TFC_DO_ENCRYPT: oper_mode = "encrypted"; break;
49 case TFC_DO_DECRYPT: oper_mode = "decrypted"; break;
51 if (ctr_mode == TFC_MODE_PLAIN) oper_mode = "written";
52 else if (ctr_mode == TFC_MODE_SKSUM) oper_mode = "hashed";
53 else oper_mode = NULL;
57 if (signal == SIGINT || signal == SIGTERM) {
61 tfc_getcurtime(¤t_time);
62 total_time += (current_time - delta_time);
63 seconds = TFC_UTODSECS(current_time - delta_time);
64 wr_speed = delta_processed / seconds;
65 tfc_describescale(total_processed_src, &human_totalproc_src, &src_scale_idx);
66 tfc_describescale(total_processed_dst, &human_totalproc_dst, &dst_scale_idx);
67 tfc_describescale(total_written_dst, &human_totalwrit_dst, &wri_scale_idx);
68 tfc_describescale(wr_speed, &human_wr_speed, &wr_speed_scale);
72 tfc_say("%s %s benchmark results:", progname, tfc_modename(ctr_mode));
73 tfc_nfsay(stdout, "%s %llu (%.2f%s) bytes, "
74 "avg. speed %llu (%.2f%s) B/s, time %.4fs.",
76 total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx),
77 wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale),
78 TFC_UTODSECS(current_time - delta_time));
83 if (do_statline_dynamic == YES) inplace = "\033[2K\r";
86 if (do_less_stats == YES) {
87 tfc_nfsay(stderr, "%s%s:"
92 human_totalproc_dst, tfc_getscale(dst_scale_idx),
93 human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
96 if (ctr_mode <= TFC_MODE_PLAIN) tfc_nfsay(stderr, "%s%s: read: %llu (%.2f%s),"
97 " %s %llu (%.2f%s) bytes,"
98 " (%llu (%.2f%s) B/s), time %s",
100 total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx),
102 total_processed_dst, human_totalproc_dst, tfc_getscale(dst_scale_idx),
103 wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
104 else tfc_nfsay(stderr, "%s%s: read: %llu (%.2f%s),"
105 " %s %s %llu (%.2f%s) bytes,"
106 " written %llu (%.2f%s) bytes,"
107 " (%llu (%.2f%s) B/s), time %s",
109 total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx),
110 tfc_modename(ctr_mode), oper_mode,
111 total_processed_dst, human_totalproc_dst, tfc_getscale(dst_scale_idx),
112 total_written_dst, human_totalwrit_dst, tfc_getscale(wri_scale_idx),
113 wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
116 if (do_stop == NO && do_statline_dynamic == NO) tfc_esay("\n");
117 if (last) tfc_esay("\n");
118 statline_was_shown = YES;
120 if ((signal == SIGINT || signal == SIGTERM) && do_stop == YES) {
122 exit_sigterm(signal);
126 tfc_getcurtime(&delta_time);
128 if (signal == SIGTSTP) kill(getpid(), SIGSTOP);
130 if (status_timer) setup_next_alarm(status_timer);
133 void change_status_width(int signal)
135 if (do_less_stats == YES) do_less_stats = NO;
136 else if (do_less_stats == NO) do_less_stats = YES;
139 void change_status_timer(int signal)
141 static tfc_useconds reset_timer;
145 if (reset_timer && (t - reset_timer) < TFC_DTOUSECS(0.1)) status_timer = 0;
148 if (status_timer == 0) status_timer = TFC_DTOUSECS(0.25);
149 else status_timer *= 2;
151 if (verbose) tfc_esay("%s: status timer was changed to %.2fs",
152 progname, TFC_UTODSECS(status_timer));
153 setup_next_alarm(status_timer);
156 void setup_next_alarm(tfc_useconds useconds)
160 memset(&it, 0, sizeof(struct itimerval));
161 it.it_value.tv_sec = useconds / 1000000;
162 it.it_value.tv_usec = useconds % 1000000;
163 setitimer(ITIMER_REAL, &it, NULL);