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 do_benchmark(tfc_useconds useconds, double dseconds)
35 for (x = 1; x < NSIG; x++) signal(x, SIG_IGN);
36 memset(&sigact, 0, sizeof(sigact));
37 sigact.sa_flags = SA_RESTART;
38 sigact.sa_handler = print_crypt_status;
39 sigaction(SIGINT, &sigact, NULL);
40 sigaction(SIGTERM, &sigact, NULL);
41 sigaction(SIGTSTP, &sigact, NULL);
42 sigaction(SIGALRM, &sigact, NULL);
43 setup_next_alarm(useconds);
44 memset(&sigact, 0, sizeof(struct sigaction));
46 tfc_getcurtime(&delta_time);
48 tfc_getrandom(key, sizeof(key));
49 tfc_getrandom(ctr, sizeof(ctr));
51 tfc_getrandom(mackey, sizeof(mackey));
52 if (ctr_mode < TFC_MODE_OCB) skein_init_key(&sk, mackey, macbits);
54 if (ctr_mode == TFC_MODE_STREAM) tfe_init_iv(&tfe, key, ctr);
55 if (ctr_mode == TFC_MODE_XTS) tfc_getrandom(xtskey, sizeof(xtskey));
57 tfc_nfsay(stdout, "%s: doing %s benchmark for %.4f seconds ... ", progname, tfc_modename(ctr_mode), dseconds);
63 lblock = blk_len_adj(NOFSIZE, total_processed_src, blksize);
64 total_processed_src += lblock;
66 if (do_mac != NO && ctr_mode < TFC_MODE_OCB)
67 skein_update(&sk, srcblk, lblock);
69 if (ctr_mode == TFC_MODE_CTR) tf_ctr_crypt(key, ctr, srcblk, srcblk, lblock);
70 else if (ctr_mode == TFC_MODE_STREAM) tf_stream_crypt(&tfe, srcblk, srcblk, lblock);
71 else if (ctr_mode == TFC_MODE_XTS && do_edcrypt == TFC_DO_ENCRYPT)
72 tf_xts_encrypt(key, xtskey, ctr, srcblk, srcblk, lblock, xtsblocks);
73 else if (ctr_mode == TFC_MODE_XTS && do_edcrypt == TFC_DO_DECRYPT)
74 tf_xts_decrypt(key, xtskey, ctr, srcblk, srcblk, lblock, xtsblocks);
75 else if (ctr_mode == TFC_MODE_ECB && do_edcrypt == TFC_DO_ENCRYPT)
76 tf_ecb_encrypt(key, srcblk, srcblk, lblock);
77 else if (ctr_mode == TFC_MODE_ECB && do_edcrypt == TFC_DO_DECRYPT)
78 tf_ecb_decrypt(key, srcblk, srcblk, lblock);
79 else if (ctr_mode == TFC_MODE_CBC && do_edcrypt == TFC_DO_ENCRYPT)
80 tf_cbc_encrypt(key, ctr, srcblk, srcblk, lblock);
81 else if (ctr_mode == TFC_MODE_CBC && do_edcrypt == TFC_DO_DECRYPT)
82 tf_cbc_decrypt(key, ctr, srcblk, srcblk, lblock);
84 else if (ctr_mode == TFC_MODE_OCB && do_edcrypt == TFC_DO_ENCRYPT)
85 tf_ocb_encrypt(key, ctr, srcblk, do_mac ? macresult : NULL, srcblk, lblock, xtsblocks);
86 else if (ctr_mode == TFC_MODE_OCB && do_edcrypt == TFC_DO_DECRYPT)
87 tf_ocb_decrypt(key, ctr, srcblk, do_mac ? macresult : NULL, srcblk, lblock, xtsblocks);
89 delta_processed += lblock;