ColinIanKing / stress-ng

This is the stress-ng upstream project git repository. stress-ng will stress test a computer system in various selectable ways. It was designed to exercise various physical subsystems of a computer as well as the various operating system kernel interfaces.
https://github.com/ColinIanKing/stress-ng
GNU General Public License v2.0
1.65k stars 272 forks source link

ecb(aes) of af-alg failed on a MTK armhf platform #47

Closed tsunghanliu closed 4 years ago

tsunghanliu commented 4 years ago

I ran the af-alg test on a MTK armhf platform (MT8516) and the ecb(aes) cipher test was failed. It showed sendmsg using ecb(aes) failed: errno=22 (Invalid argument). The following is the output of af-alg test.

$ ./stress-ng --af-alg 1 -t 1 -v --af-alg-dump
stress-ng: debug: [4242] 1 processor online, 4 processors configured
stress-ng: info:  [4242] dispatching hogs: 1 af-alg
stress-ng: info:  [4242] cache allocate: using defaults, can't determine cache details from sysfs
stress-ng: debug: [4242] cache allocate: default cache size: 2048K
stress-ng: debug: [4242] starting stressors
stress-ng: debug: [4242] 1 stressor spawned
stress-ng: debug: [4246] stress-ng-af-alg: started [4246] (instance 0)
stress-ng: info:  [4246] stress-ng-af-alg: dumping cryptographic algorithms found in /proc/crypto to stdout
{ .crypto_type = CRYPTO_AKCIPHER, .type = "akcipher", .name = "rsa" },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cipher_null",    .block_size = 1 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "digest_null",  .block_size = 1 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "md5",  .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha1", .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha256",   .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha224",   .block_size = 64,   .digest_size = 28 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha512",   .block_size = 128,  .digest_size = 64 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha384",   .block_size = 128,  .digest_size = 48 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "des",    .block_size = 8,    .max_key_size = 8 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "des3_ede",   .block_size = 8,    .max_key_size = 24 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "twofish",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "aes",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "arc4",   .block_size = 1,    .max_key_size = 256 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "crc32c",   .block_size = 1,    .digest_size = 4 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "crct10dif",    .block_size = 1,    .digest_size = 2 },
{ .crypto_type = CRYPTO_RNG, .type = "rng", .name = "stdrng" },
{ .crypto_type = CRYPTO_RNG, .type = "rng", .name = "jitterentropy_rng" },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "ghash",    .block_size = 16,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "hmac(sha256)", .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "md4",  .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd128",   .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd160",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd256",   .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd320",   .block_size = 64,   .digest_size = 40 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp512",    .block_size = 64,   .digest_size = 64 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp384",    .block_size = 64,   .digest_size = 48 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp256",    .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr192",   .block_size = 64,   .digest_size = 24 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr160",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr128",   .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "poly1305", .block_size = 16,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "michael_mic",  .block_size = 8,    .digest_size = 8 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "hmac(sha1)",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "serpent",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "tnepres",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cast6",  .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "camellia",   .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cast5",  .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "blowfish",   .block_size = 8,    .max_key_size = 56 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "tea",    .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "xtea",   .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "xeta",   .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "seed",   .block_size = 16,   .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "khazad", .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "fcrypt", .block_size = 8,    .max_key_size = 8 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "anubis", .block_size = 16,   .max_key_size = 40 },
{ .crypto_type = CRYPTO_AEAD, .type = "aead", .name = "gcm(aes)",   .block_size = 1,    .max_auth_size = 16,    .iv_size = 12 },
{ .crypto_type = CRYPTO_AEAD, .type = "aead", .name = "rfc4106(gcm(aes))",  .block_size = 1,    .max_auth_size = 16,    .iv_size = 8 },
stress-ng: info:  [4246] stress-ng-af-alg: 49 cryptographic algorithms found in /proc/crypto
stress-ng: info:  [4246] stress-ng-af-alg: 102 cryptographic algorithms max (with defconfigs)
stress-ng: debug: [4246] stress_af_alg_cipher (193): alg_cipher_info->name=ecb(aes), salg_type=skcipher
stress-ng: fail:  [4246] stress-ng-af-alg: sendmsg using ecb(aes) failed: errno=22 (Invalid argument)
stress-ng: debug: [4246] stress_af_alg_cipher (193): alg_cipher_info->name=ecb(aes), salg_type=skcipher
stress-ng: debug: [4246] stress-ng-af-alg: exited [4246] (instance 0)
stress-ng: debug: [4242] process [4246] terminated
stress-ng: info:  [4242] successful run completed in 1.33s

After some checks, I found that in /proc/crypto, the type of ecb(aes) cipher is ablkcipher. I'm not familiar with the Crypto API and didn't find what's the difference between skcipher and ablkcipher. Is this something missing in the MTK's kernel? or a case that stress-ng doesn't cover?

ColinIanKing commented 4 years ago

Which kernel version?

output from uname -a would be useful

tsunghanliu commented 4 years ago

The kernel is based on Ubuntu-4.4.0-154.181 with a bunch of MTK's patches.

I tried found that since V0.10.09, the af-alg has a different method to declare the list of algorithms, so I checkouted V0.10.08, added an entry for `ecb(aes)" to the default ciphers (as follow patched) and it didn't fail.

diff --git a/stress-af-alg.c b/stress-af-alg.c
index c0159c8..8349640 100644
--- a/stress-af-alg.c
+++ b/stress-af-alg.c
@@ -124,6 +124,7 @@ static alg_hash_info_t algo_hash_info[] = {
 };

 static alg_cipher_info_t algo_cipher_info[] = {
+       { "ecb(aes)",           SNG_AES_BLOCK_SIZE,     SNG_AES_MAX_KEY_SIZE },
        { "cbc(aes)",           SNG_AES_BLOCK_SIZE,     SNG_AES_MAX_KEY_SIZE },
        { "lrw(aes)",           SNG_AES_BLOCK_SIZE,     SNG_AES_MAX_KEY_SIZE },
        { "ofb(aes)",           SNG_AES_BLOCK_SIZE,     SNG_AES_MAX_KEY_SIZE },
tsunghanliu commented 4 years ago

After some experiments, I found in V0.10.08, the iv_size passed to sendmsg() is block_size of cipher but in V0.10.09, it's using the iv_size of the cipher.

If I switch to use block_size as iv_size (same with V0.10.08), the ecb(aes) can pass, but it will have some new failures.

diff --git a/stress-af-alg.c b/stress-af-alg.c
index 5ef83a5..7220014 100644
--- a/stress-af-alg.c
+++ b/stress-af-alg.c
@@ -184,7 +184,7 @@ static int stress_af_alg_cipher(
        int fd;
        ssize_t j;
        struct sockaddr_alg sa;
-       const ssize_t iv_size = info->iv_size;
+       const ssize_t iv_size = info->block_size;
        static char input[DATA_LEN], output[DATA_LEN];
        const char *salg_type = (info->crypto_type != CRYPTO_AEAD) ? "skcipher" : "aead";
        int retries = MAX_AF_ALG_RETRIES_BIND;
$ ./stress-ng --af-alg 1 -t 2 --af-alg-dump -v
stress-ng: debug: [18076] 3 processors online, 4 processors configured
stress-ng: info:  [18076] dispatching hogs: 1 af-alg
stress-ng: info:  [18076] cache allocate: using defaults, can't determine cache details from sysfs
stress-ng: debug: [18076] cache allocate: default cache size: 2048K
stress-ng: debug: [18076] starting stressors
stress-ng: debug: [18076] 1 stressor spawned
stress-ng: debug: [18077] stress-ng-af-alg: started [18077] (instance 0)
stress-ng: info:  [18077] stress-ng-af-alg: dumping cryptographic algorithms found in /proc/crypto to stdout
{ .crypto_type = CRYPTO_AKCIPHER, .type = "akcipher", .name = "rsa" },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cipher_null",    .block_size = 1 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "digest_null",  .block_size = 1 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "md5",  .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha1", .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha256",   .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha224",   .block_size = 64,   .digest_size = 28 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha512",   .block_size = 128,  .digest_size = 64 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha384",   .block_size = 128,  .digest_size = 48 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "des",    .block_size = 8,    .max_key_size = 8 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "des3_ede",   .block_size = 8,    .max_key_size = 24 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "twofish",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "aes",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "arc4",   .block_size = 1,    .max_key_size = 256 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "crc32c",   .block_size = 1,    .digest_size = 4 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "crct10dif",    .block_size = 1,    .digest_size = 2 },
{ .crypto_type = CRYPTO_RNG, .type = "rng", .name = "stdrng" },
{ .crypto_type = CRYPTO_RNG, .type = "rng", .name = "jitterentropy_rng" },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "ghash",    .block_size = 16,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "hmac(sha256)", .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "serpent",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "tnepres",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cast6",  .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "camellia",   .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cast5",  .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "blowfish",   .block_size = 8,    .max_key_size = 56 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp512",    .block_size = 64,   .digest_size = 64 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp384",    .block_size = 64,   .digest_size = 48 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp256",    .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr192",   .block_size = 64,   .digest_size = 24 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr160",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr128",   .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd320",   .block_size = 64,   .digest_size = 40 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd256",   .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd160",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd128",   .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "poly1305", .block_size = 16,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "michael_mic",  .block_size = 8,    .digest_size = 8 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "md4",  .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "hmac(sha1)",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "tea",    .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "xtea",   .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "xeta",   .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "seed",   .block_size = 16,   .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "khazad", .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "fcrypt", .block_size = 8,    .max_key_size = 8 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "anubis", .block_size = 16,   .max_key_size = 40 },
{ .crypto_type = CRYPTO_AEAD, .type = "aead", .name = "gcm(aes)",   .block_size = 1,    .max_auth_size = 16,    .iv_size = 12 },
{ .crypto_type = CRYPTO_AEAD, .type = "aead", .name = "rfc4106(gcm(aes))",  .block_size = 1,    .max_auth_size = 16,    .iv_size = 8 },
stress-ng: info:  [18077] stress-ng-af-alg: 49 cryptographic algorithms found in /proc/crypto
stress-ng: info:  [18077] stress-ng-af-alg: 102 cryptographic algorithms max (with defconfigs)
stress-ng: fail:  [18077] stress-ng-af-alg: sendmsg using salsa20 failed: errno=22 (Invalid argument)
stress-ng: fail:  [18077] stress-ng-af-alg: sendmsg using ecb(twofish) failed: errno=22 (Invalid argument)
stress-ng: fail:  [18077] stress-ng-af-alg: sendmsg using ecb(serpent) failed: errno=22 (Invalid argument)
stress-ng: fail:  [18077] stress-ng-af-alg: sendmsg using ecb(des3_ede) failed: errno=22 (Invalid argument)
stress-ng: fail:  [18077] stress-ng-af-alg: sendmsg using ecb(cipher_null) failed: errno=22 (Invalid argument)
info: 5 failures reached, aborting stress process
stress-ng: debug: [18077] stress-ng-af-alg: exited [18077] (instance 0)
stress-ng: error: [18076] process 18077 (stress-ng-af-alg) terminated with an error, exit status=1 (stress-ng core failure)
stress-ng: debug: [18076] process [18077] terminated
stress-ng: info:  [18076] unsuccessful run completed in 0.35s
tsunghanliu commented 4 years ago

I am thinking if it's a reasonable fix that when sendmsg() returns a EINVAL error then set the block_size of cipher as iv_size. Or it's a bug of the kernel I'm using?

diff --git a/stress-af-alg.c b/stress-af-alg.c
index 5ef83a5..fd1f3ff 100644
--- a/stress-af-alg.c
+++ b/stress-af-alg.c
@@ -184,7 +184,7 @@ static int stress_af_alg_cipher(
        int fd;
        ssize_t j;
        struct sockaddr_alg sa;
-       const ssize_t iv_size = info->iv_size;
+       ssize_t iv_size = info->iv_size;
        static char input[DATA_LEN], output[DATA_LEN];
        const char *salg_type = (info->crypto_type != CRYPTO_AEAD) ? "skcipher" : "aead";
        int retries = MAX_AF_ALG_RETRIES_BIND;
@@ -297,6 +297,15 @@ retry_bind:
                if (sendmsg(fd, &msg, 0) < 0) {
                        if (errno == ENOMEM)
                                break;
+                       if (errno == EINVAL) {
+                               if (info->block_size != iv_size) {
+                                       pr_dbg("%s: sendmsg using %s failed, try to use blk_size as iv_size\n",
+                                               args->name, info->name);
+                                       iv_size = info->block_size;
+                                       continue;
+                               }
+                               break;
+                       }
                        pr_fail("%s: sendmsg using %s failed: errno=%d (%s)\n",
                                args->name, info->name,
                                errno, strerror(errno));
$ ./stress-ng --af-alg 1 -t 2 --af-alg-dump -v
stress-ng: debug: [614] 2 processors online, 4 processors configured
stress-ng: info:  [614] dispatching hogs: 1 af-alg
stress-ng: info:  [614] cache allocate: using defaults, can't determine cache details from sysfs
stress-ng: debug: [614] cache allocate: default cache size: 2048K
stress-ng: debug: [614] starting stressors
stress-ng: debug: [614] 1 stressor spawned
stress-ng: debug: [615] stress-ng-af-alg: started [615] (instance 0)
stress-ng: info:  [615] stress-ng-af-alg: dumping cryptographic algorithms found in /proc/crypto to stdout
{ .crypto_type = CRYPTO_AKCIPHER, .type = "akcipher", .name = "rsa" },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cipher_null",    .block_size = 1 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "digest_null",  .block_size = 1 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "md5",  .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha1", .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha256",   .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha224",   .block_size = 64,   .digest_size = 28 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha512",   .block_size = 128,  .digest_size = 64 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "sha384",   .block_size = 128,  .digest_size = 48 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "des",    .block_size = 8,    .max_key_size = 8 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "des3_ede",   .block_size = 8,    .max_key_size = 24 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "twofish",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "aes",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "arc4",   .block_size = 1,    .max_key_size = 256 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "crc32c",   .block_size = 1,    .digest_size = 4 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "crct10dif",    .block_size = 1,    .digest_size = 2 },
{ .crypto_type = CRYPTO_RNG, .type = "rng", .name = "stdrng" },
{ .crypto_type = CRYPTO_RNG, .type = "rng", .name = "jitterentropy_rng" },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "ghash",    .block_size = 16,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "hmac(sha256)", .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "serpent",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "tnepres",    .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cast6",  .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "camellia",   .block_size = 16,   .max_key_size = 32 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "cast5",  .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "blowfish",   .block_size = 8,    .max_key_size = 56 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp512",    .block_size = 64,   .digest_size = 64 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp384",    .block_size = 64,   .digest_size = 48 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "wp256",    .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr192",   .block_size = 64,   .digest_size = 24 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr160",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "tgr128",   .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd320",   .block_size = 64,   .digest_size = 40 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd256",   .block_size = 64,   .digest_size = 32 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd160",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "rmd128",   .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "poly1305", .block_size = 16,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "michael_mic",  .block_size = 8,    .digest_size = 8 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "md4",  .block_size = 64,   .digest_size = 16 },
{ .crypto_type = CRYPTO_SHASH, .type = "shash", .name = "hmac(sha1)",   .block_size = 64,   .digest_size = 20 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "tea",    .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "xtea",   .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "xeta",   .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "seed",   .block_size = 16,   .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "khazad", .block_size = 8,    .max_key_size = 16 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "fcrypt", .block_size = 8,    .max_key_size = 8 },
{ .crypto_type = CRYPTO_CIPHER, .type = "cipher", .name = "anubis", .block_size = 16,   .max_key_size = 40 },
{ .crypto_type = CRYPTO_AEAD, .type = "aead", .name = "gcm(aes)",   .block_size = 1,    .max_auth_size = 16,    .iv_size = 12 },
{ .crypto_type = CRYPTO_AEAD, .type = "aead", .name = "rfc4106(gcm(aes))",  .block_size = 1,    .max_auth_size = 16,    .iv_size = 8 },
stress-ng: info:  [615] stress-ng-af-alg: 49 cryptographic algorithms found in /proc/crypto
stress-ng: info:  [615] stress-ng-af-alg: 102 cryptographic algorithms max (with defconfigs)
stress-ng: debug: [615] stress-ng-af-alg: sendmsg using ecb(aes) failed, try to use blk_size as iv_size
stress-ng: debug: [615] stress-ng-af-alg: sendmsg using ecb(aes) failed, try to use blk_size as iv_size
stress-ng: debug: [615] stress-ng-af-alg: sendmsg using ecb(aes) failed, try to use blk_size as iv_size
stress-ng: debug: [615] stress-ng-af-alg: exited [615] (instance 0)
stress-ng: debug: [614] process [615] terminated
stress-ng: info:  [614] successful run completed in 2.15s
ColinIanKing commented 4 years ago

I believe it may be a kernel issue, but I don't have the exact kernel as you do, so I can't easily debug this. I think probably on an -EINVAL we just internally flag this up as an algorithm that is not functioning as expected and issue a warning message first time it happens. Is that OK?

ColinIanKing commented 4 years ago

Workaround pushed: https://github.com/ColinIanKing/stress-ng/commit/20a571b1d1abe34c7db1d608179add675ae57193

tsunghanliu commented 4 years ago

@ColinIanKing Thanks for your help :)