]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - crypto/tcrypt.c
crypto: drbg - Use Kconfig to ensure at least one RNG option is set
[mirror_ubuntu-bionic-kernel.git] / crypto / tcrypt.c
index 870be7b4dc0529b1a9722e569eaccd71092623e3..c48d07857a2bad650ed4b2d34faa25881b38b2d6 100644 (file)
 #define ENCRYPT 1
 #define DECRYPT 0
 
+/*
+ * return a string with the driver name
+ */
+#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
+
 /*
  * Used by test_cipher_speed()
  */
@@ -282,6 +287,11 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,
        unsigned int *b_size;
        unsigned int iv_len;
 
+       if (aad_size >= PAGE_SIZE) {
+               pr_err("associate data length (%u) too big\n", aad_size);
+               return;
+       }
+
        if (enc == ENCRYPT)
                e = "encryption";
        else
@@ -300,22 +310,22 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,
        asg = &sg[8];
        sgout = &asg[8];
 
-
-       printk(KERN_INFO "\ntesting speed of %s %s\n", algo, e);
-
        tfm = crypto_alloc_aead(algo, 0, 0);
 
        if (IS_ERR(tfm)) {
                pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
                       PTR_ERR(tfm));
-               return;
+               goto out_notfm;
        }
 
+       printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
+                       get_driver_name(crypto_aead, tfm), e);
+
        req = aead_request_alloc(tfm, GFP_KERNEL);
        if (!req) {
                pr_err("alg: aead: Failed to allocate request for %s\n",
                       algo);
-               goto out;
+               goto out_noreq;
        }
 
        i = 0;
@@ -323,14 +333,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,
                b_size = aead_sizes;
                do {
                        assoc = axbuf[0];
-
-                       if (aad_size < PAGE_SIZE)
-                               memset(assoc, 0xff, aad_size);
-                       else {
-                               pr_err("associate data length (%u) too big\n",
-                                       aad_size);
-                               goto out_nosg;
-                       }
+                       memset(assoc, 0xff, aad_size);
                        sg_init_one(&asg[0], assoc, aad_size);
 
                        if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
@@ -392,7 +395,10 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,
        } while (*keysize);
 
 out:
+       aead_request_free(req);
+out_noreq:
        crypto_free_aead(tfm);
+out_notfm:
        kfree(sg);
 out_nosg:
        testmgr_free_buf(xoutbuf);
@@ -421,8 +427,6 @@ static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
        else
                e = "decryption";
 
-       printk("\ntesting speed of %s %s\n", algo, e);
-
        tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
 
        if (IS_ERR(tfm)) {
@@ -433,6 +437,9 @@ static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
        desc.tfm = tfm;
        desc.flags = 0;
 
+       printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
+                       get_driver_name(crypto_blkcipher, tfm), e);
+
        i = 0;
        do {
 
@@ -682,8 +689,6 @@ static void test_hash_speed(const char *algo, unsigned int sec,
        int i;
        int ret;
 
-       printk(KERN_INFO "\ntesting speed of %s\n", algo);
-
        tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
 
        if (IS_ERR(tfm)) {
@@ -692,6 +697,9 @@ static void test_hash_speed(const char *algo, unsigned int sec,
                return;
        }
 
+       printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
+                       get_driver_name(crypto_hash, tfm));
+
        desc.tfm = tfm;
        desc.flags = 0;
 
@@ -920,8 +928,6 @@ static void test_ahash_speed(const char *algo, unsigned int sec,
        static char output[1024];
        int i, ret;
 
-       printk(KERN_INFO "\ntesting speed of async %s\n", algo);
-
        tfm = crypto_alloc_ahash(algo, 0, 0);
        if (IS_ERR(tfm)) {
                pr_err("failed to load transform for %s: %ld\n",
@@ -929,6 +935,9 @@ static void test_ahash_speed(const char *algo, unsigned int sec,
                return;
        }
 
+       printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
+                       get_driver_name(crypto_ahash, tfm));
+
        if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
                pr_err("digestsize(%u) > outputbuffer(%zu)\n",
                       crypto_ahash_digestsize(tfm), sizeof(output));
@@ -1082,8 +1091,6 @@ static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
        else
                e = "decryption";
 
-       pr_info("\ntesting speed of async %s %s\n", algo, e);
-
        init_completion(&tresult.completion);
 
        tfm = crypto_alloc_ablkcipher(algo, 0, 0);
@@ -1094,6 +1101,9 @@ static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
                return;
        }
 
+       pr_info("\ntesting speed of async %s (%s) %s\n", algo,
+                       get_driver_name(crypto_ablkcipher, tfm), e);
+
        req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
        if (!req) {
                pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
@@ -1518,7 +1528,36 @@ static int do_test(int m)
        case 157:
                ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
                break;
-
+       case 181:
+               ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
+               break;
+       case 182:
+               ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
+               break;
+       case 183:
+               ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
+               break;
+       case 184:
+               ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
+               break;
+       case 185:
+               ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
+               break;
+       case 186:
+               ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
+               break;
+       case 187:
+               ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
+               break;
+       case 188:
+               ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
+               break;
+       case 189:
+               ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
+               break;
+       case 190:
+               ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
+               break;
        case 200:
                test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
                                speed_template_16_24_32);
@@ -1555,6 +1594,12 @@ static int do_test(int m)
                test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
                                des3_speed_template, DES3_SPEED_VECTORS,
                                speed_template_24);
+               test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
+                               des3_speed_template, DES3_SPEED_VECTORS,
+                               speed_template_24);
+               test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
+                               des3_speed_template, DES3_SPEED_VECTORS,
+                               speed_template_24);
                break;
 
        case 202: