mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 12:20:00 +01:00
Change PBKDF interface API.
Prepare API for PBKDF that can set three costs - time (similar to iterations in PBKDF2) - memory (required memory for memory-hard function) - threads (required number of threads/CPUs). This patch also removes wrongly designed API call crypt_benchmark_kdf and replaces it with the new call crypt_benchmark_pbkdf. Two functions for PBKDF per context setting are introduced: crypt_set_pbkdf_type and crypt_get_pbkdf_type. The patch should be backward compatible when using crypt_set_iteration_time function (works only for PBKDF2). Signed-off-by: Milan Broz <gmazyland@gmail.com>
This commit is contained in:
@@ -529,18 +529,28 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int action_benchmark_kdf(const char *hash)
|
||||
static int action_benchmark_kdf(const char *kdf, const char *hash, size_t key_size)
|
||||
{
|
||||
uint64_t kdf_iters;
|
||||
int r;
|
||||
if (!strcmp(kdf, CRYPT_KDF_PBKDF2)) {
|
||||
const struct crypt_pbkdf_type pbkdf = {
|
||||
.type = CRYPT_KDF_PBKDF2,
|
||||
.hash = hash,
|
||||
.time_ms = 1000,
|
||||
};
|
||||
uint32_t kdf_iters;
|
||||
|
||||
r = crypt_benchmark_kdf(NULL, "pbkdf2", hash, "foo", 3, "bar", 3,
|
||||
&kdf_iters);
|
||||
if (r < 0)
|
||||
log_std("PBKDF2-%-9s N/A\n", hash);
|
||||
else
|
||||
log_std("PBKDF2-%-9s %7" PRIu64 " iterations per second for %d-bit key\n",
|
||||
hash, kdf_iters, DEFAULT_LUKS1_KEYBITS);
|
||||
r = crypt_benchmark_pbkdf(NULL, &pbkdf, "foo", 3, "bar", 3, key_size,
|
||||
&kdf_iters, NULL);
|
||||
if (r < 0)
|
||||
log_std("PBKDF2-%-9s N/A\n", hash);
|
||||
else
|
||||
log_std("PBKDF2-%-9s %7u iterations per second for %zu-bit key\n",
|
||||
hash, kdf_iters, key_size * 8);
|
||||
} else {
|
||||
log_err("Unknown PBKDF '%s'\n", kdf);
|
||||
r = -EINVAL;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -594,15 +604,13 @@ static int action_benchmark(void)
|
||||
};
|
||||
char cipher[MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN];
|
||||
double enc_mbr = 0, dec_mbr = 0;
|
||||
int key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS);
|
||||
int key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS) / 8;
|
||||
int iv_size = 16, skipped = 0;
|
||||
char *c;
|
||||
int i, r;
|
||||
|
||||
log_std(_("# Tests are approximate using memory only (no storage IO).\n"));
|
||||
if (opt_hash) {
|
||||
r = action_benchmark_kdf(opt_hash);
|
||||
} else if (opt_cipher) {
|
||||
if (opt_cipher) {
|
||||
r = crypt_parse_name_and_mode(opt_cipher, cipher, NULL, cipher_mode);
|
||||
if (r < 0) {
|
||||
log_err(_("No known cipher specification pattern detected.\n"));
|
||||
@@ -621,17 +629,17 @@ static int action_benchmark(void)
|
||||
iv_size = 0;
|
||||
|
||||
r = benchmark_cipher_loop(cipher, cipher_mode,
|
||||
key_size / 8, iv_size,
|
||||
key_size, iv_size,
|
||||
&enc_mbr, &dec_mbr);
|
||||
if (!r) {
|
||||
log_std(N_("# Algorithm | Key | Encryption | Decryption\n"));
|
||||
log_std("%11s-%s %4db %6.1f MiB/s %6.1f MiB/s\n",
|
||||
cipher, cipher_mode, key_size, enc_mbr, dec_mbr);
|
||||
cipher, cipher_mode, key_size*8, enc_mbr, dec_mbr);
|
||||
} else if (r == -ENOENT)
|
||||
log_err(_("Cipher %s is not available.\n"), opt_cipher);
|
||||
} else {
|
||||
for (i = 0; bkdfs[i]; i++) {
|
||||
r = action_benchmark_kdf(bkdfs[i]);
|
||||
r = action_benchmark_kdf(CRYPT_KDF_PBKDF2, bkdfs[i], key_size);
|
||||
check_signal(&r);
|
||||
if (r == -EINTR)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user