Better tcrypt test options.

This commit is contained in:
Milan Broz
2012-11-30 15:03:01 +01:00
parent 4f7262aa96
commit 0461d9e822
3 changed files with 48 additions and 8 deletions

View File

@@ -344,6 +344,8 @@ static int decrypt_hdr_cbci(struct tcrypt_algs *ciphers,
memcpy(iv, &key[ciphers->cipher[0].iv_offset], bs);
/* Initialize all ciphers in chain in ECB mode */
for (j = 0; j < ciphers->chain_count; j++)
cipher[j] = NULL;
for (j = 0; j < ciphers->chain_count; j++) {
r = crypt_cipher_init(&cipher[j], ciphers->cipher[j].name, "ecb",
&key[ciphers->cipher[j].key_offset],
@@ -377,7 +379,7 @@ static int decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
const char *key, int legacy_modes)
{
struct tcrypt_phdr hdr2;
int i, j, r;
int i, j, r = -EINVAL;
for (i = 0; tcrypt_cipher[i].chain_count; i++) {
if (!legacy_modes && tcrypt_cipher[i].legacy)

View File

@@ -458,7 +458,7 @@ static int action_benchmark(int arg __attribute__((unused)))
{ NULL, NULL, 0, 0 }
};
char *header = "# Tests are approximate using memory only (no storage IO).\n"
"# Algorithm | Key | Encryption | Decryption\n";
"# Algorithm | Key | Encryption | Decryption\n";
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);
@@ -477,7 +477,9 @@ static int action_benchmark(int arg __attribute__((unused)))
*c = '\0';
/* FIXME: not really clever :) */
if (strstr(cipher, "des"))
if (strstr(cipher, "des") ||
strstr(cipher, "blowfish") ||
strstr(cipher, "cast5"))
iv_size = 8;
r = crypt_benchmark(NULL, cipher, cipher_mode,
@@ -487,7 +489,7 @@ static int action_benchmark(int arg __attribute__((unused)))
log_std("%s", header);
strncat(cipher, "-", MAX_CIPHER_LEN);
strncat(cipher, cipher_mode, MAX_CIPHER_LEN);
log_std("%11s %4db %5.1f MiB/s %5.1f MiB/s\n",
log_std("%12s %4db %5.1f MiB/s %5.1f MiB/s\n",
cipher, key_size, enc_mbr, dec_mbr);
} else if (r == -ENOENT)
log_err(_("Cipher %s is not available.\n"), opt_cipher);
@@ -506,10 +508,10 @@ static int action_benchmark(int arg __attribute__((unused)))
snprintf(cipher, MAX_CIPHER_LEN, "%s-%s",
bciphers[i].cipher, bciphers[i].mode);
if (!r)
log_std("%11s %4db %5.1f MiB/s %5.1f MiB/s\n",
log_std("%12s %4db %5.1f MiB/s %5.1f MiB/s\n",
cipher, bciphers[i].key_size*8, enc_mbr, dec_mbr);
else
log_std("%11s %4db %12s %12s\n", cipher,
log_std("%12s %4db %12s %12s\n", cipher,
bciphers[i].key_size*8, _("N/A"), _("N/A"));
}
if (skipped && skipped == i)

View File

@@ -18,11 +18,47 @@ function remove_mapping()
function fail()
{
[ -n "$1" ] && echo "$1"
echo "FAILED"
echo " [FAILED]"
remove_mapping
exit 2
}
function skip()
{
[ -n "$1" ] && echo "$1"
echo "Test skipped."
exit 0
}
function test_one()
{
$CRYPTSETUP benchmark -c "$1" -s "$2" | grep -v "#" || skip
}
function test_required()
{
echo "REQUIRED CIPHERS TEST"
echo "# Algorithm | Key | Encryption | Decryption"
test_one aes-cbc 256
test_one aes-lrw 384
test_one aes-xts 512
test_one twofish-cbc 256
test_one twofish-lrw 384
test_one twofish-xts 512
test_one serpent-cbc 256
test_one serpent-lrw 384
test_one serpent-xts 512
test_one blowfish-cbc 256
test_one des3_ede-cbc 192
test_one cast5 128
}
test_required
[ ! -d $TST_DIR ] && tar xjf tcrypt-images.tar.bz2
@@ -41,7 +77,7 @@ for file in $(ls $TST_DIR/tc_*-hidden) ; do
done
if [ $(id -u) != 0 ]; then
echo "WARNING: You must be root to run this test, test skipped."
echo "WARNING: You must be root to run activation part of test, test skipped."
exit 0
fi