X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Futils_benchmark.c;h=728e4dfd1be61f54ecd0bbfdf45a785f5afa50f9;hb=6497abd1df88001eb1f45f7348534911b33d05b5;hp=6b2efdcd76fa701e77dfea4f92c10855ccbc1598;hpb=f7fc3bb4e50cce23dd95111b246b6e034537e2cf;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/lib/utils_benchmark.c b/lib/utils_benchmark.c index 6b2efdc..728e4df 100644 --- a/lib/utils_benchmark.c +++ b/lib/utils_benchmark.c @@ -1,8 +1,8 @@ /* * libcryptsetup - cryptsetup library, cipher benchmark * - * Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved. - * Copyright (C) 2012-2021 Milan Broz + * Copyright (C) 2012-2023 Red Hat, Inc. All rights reserved. + * Copyright (C) 2012-2023 Milan Broz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -47,6 +47,7 @@ int crypt_benchmark(struct crypt_device *cd, r = -ENOMEM; if (posix_memalign(&buffer, crypt_getpagesize(), buffer_size)) goto out; + memset(buffer, 0, buffer_size); r = crypt_cipher_ivsize(cipher, cipher_mode); if (r >= 0 && iv_size != (size_t)r) { @@ -98,7 +99,7 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd, int (*progress)(uint32_t time_ms, void *usrptr), void *usrptr) { - int r; + int r, priority; const char *kdf_opt; if (!pbkdf || (!password && password_size)) @@ -112,10 +113,12 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd, log_dbg(cd, "Running %s(%s) benchmark.", pbkdf->type, kdf_opt); + crypt_process_priority(cd, &priority, true); r = crypt_pbkdf_perf(pbkdf->type, pbkdf->hash, password, password_size, salt, salt_size, volume_key_size, pbkdf->time_ms, pbkdf->max_memory_kb, pbkdf->parallel_threads, &pbkdf->iterations, &pbkdf->max_memory_kb, progress, usrptr); + crypt_process_priority(cd, &priority, false); if (!r) log_dbg(cd, "Benchmark returns %s(%s) %u iterations, %u memory, %u threads (for %zu-bits key).", @@ -184,7 +187,7 @@ int crypt_benchmark_pbkdf_internal(struct crypt_device *cd, pbkdf->parallel_threads = 0; /* N/A in PBKDF2 */ pbkdf->max_memory_kb = 0; /* N/A in PBKDF2 */ - r = crypt_benchmark_pbkdf(cd, pbkdf, "foo", 3, "bar", 3, + r = crypt_benchmark_pbkdf(cd, pbkdf, "foobarfo", 8, "01234567890abcdef", 16, volume_key_size, &benchmark_callback, &u); pbkdf->time_ms = ms_tmp; if (r < 0) { @@ -196,7 +199,7 @@ int crypt_benchmark_pbkdf_internal(struct crypt_device *cd, PBKDF2_tmp = ((double)pbkdf->iterations * pbkdf->time_ms / 1000.); if (PBKDF2_tmp > (double)UINT32_MAX) return -EINVAL; - pbkdf->iterations = at_least((uint32_t)PBKDF2_tmp, pbkdf_limits.min_iterations); + pbkdf->iterations = AT_LEAST((uint32_t)PBKDF2_tmp, pbkdf_limits.min_iterations); } else { /* Already benchmarked */ if (pbkdf->iterations) { @@ -204,7 +207,7 @@ int crypt_benchmark_pbkdf_internal(struct crypt_device *cd, return 0; } - r = crypt_benchmark_pbkdf(cd, pbkdf, "foo", 3, + r = crypt_benchmark_pbkdf(cd, pbkdf, "foobarfo", 8, "0123456789abcdef0123456789abcdef", 32, volume_key_size, &benchmark_callback, &u); if (r < 0)