Only check current clock() on every 32-th cycle, in order to limit the overhead.

This commit is contained in:
LoRd_MuldeR 2021-03-28 16:17:06 +02:00
parent 73f2e71342
commit 163dee5e9d
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
2 changed files with 22 additions and 12 deletions

View File

@ -317,7 +317,8 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co
goto clean_up;
}
clock_t clk_now, clk_update = clock();
unsigned refresh_cycles = 0U;
clock_t clk_update = clock();
uint64_t bytes_read = 0U;
uint8_t buffer[BUFFER_SIZE];
@ -351,13 +352,17 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co
{
break; /*EOF*/
}
if ((clk_now = clock()) - clk_update > UPDATE_INTERVAL)
if (!(++refresh_cycles & 0x1F))
{
const clock_t clk_now = clock();
if ((clk_now < clk_update) || (clk_now - clk_update > UPDATE_INTERVAL))
{
FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%% "), (bytes_read / ((double)file_size)) * 100.0);
fflush(stderr);
clk_update = clk_now;
}
}
}
if (ferror(file_in))
{
@ -488,9 +493,11 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co
goto clean_up;
}
clock_t clk_now, clk_update = clock();
unsigned refresh_cycles = 0U;
clock_t clk_update = clock();
uint64_t bytes_read = sizeof(uint64_t);
uint8_t buffer[BUFFER_SIZE];
const uint64_t read_limit = round_down(file_size, sizeof(uint64_t)) - (2U * sizeof(uint64_t));
blake2s_t blake2s_state;
@ -523,13 +530,17 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co
{
break; /*EOF*/
}
if ((clk_now = clock()) - clk_update > UPDATE_INTERVAL)
if (!(++refresh_cycles & 0x1F))
{
const clock_t clk_now = clock();
if ((clk_now < clk_update) || (clk_now - clk_update > UPDATE_INTERVAL))
{
FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%% "), (bytes_read / ((double)read_limit)) * 100.0);
fflush(stderr);
clk_update = clk_now;
}
}
}
if (ferror(file_in))
{

View File

@ -242,8 +242,7 @@ static int initialize_state(crypt_state_t* const crypt_state, const uint64_t non
}
for (i = 0U; i < 256U; ++i)
{
const size_t j = crypt_state->wheel_fwd[r][i];
crypt_state->wheel_bwd[255U - r][j] = (uint8_t)i;
crypt_state->wheel_bwd[255U - r][crypt_state->wheel_fwd[r][i]] = (uint8_t)i;
}
CHECK_ABORTED();
}