Hi Herbert,

the attached patch makes the use of tcrypt.ko more convenient. Tests can
now be called with algorithm name as a parameter. That frees us from
reading the source and looking for the correct constant every time one
wants to use the module.

It's not a rocket science. It does, however, introduce backward
incompatibility. But I don't think that would be a problem - it's a
module only for testing anyway.

Michal
-- 
* Personal homepage: http://www.logix.cz/michal



The interface to tcrypt.ko was until now driven by magic code 
numbers with no apparent meaning. This patch enables invocation 
of different tests and benchmarks by algorithm name instead of
by those meaningles numbers. A special algorithm name "all" is 
here to invoke all tests in a given category. Currently we support
four test categories (basic tests, hmac tests, speed tests and 
availability tests). See "modinfo tcrypt" for details on how to 
select the desired category.

Signed-off-by: Michal Ludvig <[EMAIL PROTECTED]>

Index: linux/crypto/tcrypt.c
===================================================================
--- linux.orig/crypto/tcrypt.c
+++ linux/crypto/tcrypt.c
@@ -64,15 +64,45 @@ static unsigned int IDX[8] = { IDX1, IDX
  */
 static unsigned int sec;
 
-static int mode;
+static char *name_test, *name_hmac, *name_speed, *name_available;
+static int   mode_test,  mode_hmac,  mode_speed,  mode_available;
 static char *xbuf;
 static char *tvmem;
 
-static char *check[] = {
-	"des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
-	"twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
-	"arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
-	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
+static struct name_id_map map[] = {
+	{ .name = "all",	.id = ALG_ALL },
+	{ .name = "des",	.id = ALG_DES },
+	{ .name = "md5",	.id = ALG_MD5 },
+	{ .name = "des3_ede",	.id = ALG_DES3_EDE },
+	{ .name = "rot13",	.id = ALG_ROT13 },
+	{ .name = "sha1",	.id = ALG_SHA1 },
+	{ .name = "sha256",	.id = ALG_SHA256 },
+	{ .name = "blowfish",	.id = ALG_BLOWFISH },
+	{ .name = "twofish",	.id = ALG_TWOFISH },
+	{ .name = "serpent",	.id = ALG_SERPENT },
+	{ .name = "sha384",	.id = ALG_SHA384 },
+	{ .name = "sha512",	.id = ALG_SHA512 },
+	{ .name = "md4",	.id = ALG_MD4 },
+	{ .name = "aes",	.id = ALG_AES },
+	{ .name = "cast5",	.id = ALG_CAST5 },
+	{ .name = "cast6",	.id = ALG_CAST6 },
+	{ .name = "arc4",	.id = ALG_ARC4 },
+	{ .name = "michael_mic",.id = ALG_MICHAEL_MIC },
+	{ .name = "deflate",	.id = ALG_DEFLATE },
+	{ .name = "crc32c",	.id = ALG_CRC32C },
+	{ .name = "tea",	.id = ALG_TEA },
+	{ .name = "xtea",	.id = ALG_XTEA },
+	{ .name = "khazad",	.id = ALG_KHAZAD },
+	{ .name = "wp512",	.id = ALG_WP512 },
+	{ .name = "wp384",	.id = ALG_WP384 },
+	{ .name = "wp256",	.id = ALG_WP256 },
+	{ .name = "tnepres",	.id = ALG_TNEPRES },
+	{ .name = "xeta",	.id = ALG_XETA },
+	{ .name = "anubis",	.id = ALG_ANUBIS },
+	{ .name = "tgr192",	.id = ALG_TGR192 },
+	{ .name = "tgr160",	.id = ALG_TGR160 },
+	{ .name = "tgr128",	.id = ALG_TGR128 },
+	{ .name = NULL,		.id = 0 }
 };
 
 static void hexdump(unsigned char *buf, unsigned int len)
@@ -83,6 +113,36 @@ static void hexdump(unsigned char *buf, 
 	printk("\n");
 }
 
+static enum alg_ids name_to_id(const char *name)
+{
+	struct name_id_map *algo = map;
+
+	if (!name)
+		return ALG_NONE;
+
+	while (algo->name) {
+		if (strcmp(algo->name, name) == 0)
+			return algo->id;
+		algo++;
+	}
+
+	printk("Unknown algorithm '%s'.\n", name);
+	return ALG_NONE;
+}
+
+#if 0 /* not used */
+static const char *id_to_name(enum alg_ids id)
+{
+	struct name_id_map *algo = map;
+	while (algo->name) {
+		if (algo->id == id)
+			return algo->name;
+		algo++;
+	}
+	return NULL;
+}
+#endif
+
 static void test_hash(char *algo, struct hash_testvec *template,
 		      unsigned int tcount)
 {
@@ -749,281 +809,204 @@ static void test_crc32c(void)
 
 static void test_available(void)
 {
-	char **name = check;
-
-	while (*name) {
-		printk("alg %s ", *name);
-		printk((crypto_alg_available(*name, 0)) ?
-			"found\n" : "not found\n");
-		name++;
+	struct name_id_map *algo = map;
+	while (algo->name) {
+		if ((mode_available == ALG_ALL) || (mode_available == algo->id)) {
+			printk("alg %s ", algo->name);
+			printk((crypto_alg_available(algo->name, 0)) ?
+				"found\n" : "not found\n");
+		}
+		algo++;
 	}
 }
 
 static void do_test(void)
 {
-	switch (mode) {
-
-	case 0:
-		test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
-
-		test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
-
-		//DES
-		test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
-		test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
-		test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
-		test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
-
-		//DES3_EDE
-		test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
-		test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
-
-		test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
-
-		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
-
-		//BLOWFISH
-		test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
-		test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
-		test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
-		test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
-
-		//TWOFISH
-		test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
-		test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
-		test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
-		test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
-
-		//SERPENT
-		test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
-		test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
-
-		//TNEPRES
-		test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
-		test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
-
-		//AES
-		test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
-		test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
-		test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
-		test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
-
-		//CAST5
-		test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
-		test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
-
-		//CAST6
-		test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
-		test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
-
-		//ARC4
-		test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
-		test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
-
-		//TEA
-		test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
-		test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
-
-
-		//XTEA
-		test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
-		test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
-
-		//KHAZAD
-		test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
-		test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
-
-		//ANUBIS
-		test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
-		test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
-		test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
-		test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
-
-		//XETA
-		test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
-		test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
-
-		test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
-		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
-		test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
-		test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
-		test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
-		test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
-		test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
-		test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
-		test_deflate();
-		test_crc32c();
-#ifdef CONFIG_CRYPTO_HMAC
-		test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
-		test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
-		test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
-#endif
+	if (mode_test > ALG_NONE)
+	switch (mode_test) {
 
-		test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
-		break;
+	case ALG_ALL:
 
-	case 1:
+	case ALG_MD5:
 		test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 2:
+	case ALG_SHA1:
 		test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 3:
+	case ALG_DES:
 		test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
 		test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
 		test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
 		test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 4:
+	case ALG_DES3_EDE:
 		test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
 		test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 5:
+	case ALG_MD4:
 		test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 6:
+	case ALG_SHA256:
 		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 7:
+	case ALG_BLOWFISH:
 		test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
 		test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
 		test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
 		test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 8:
+	case ALG_TWOFISH:
 		test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
 		test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
 		test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
 		test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 9:
+	case ALG_SERPENT:
 		test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
 		test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 10:
+	case ALG_AES:
 		test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
 		test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
 		test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
 		test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 11:
+	case ALG_SHA384:
 		test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 12:
+	case ALG_SHA512:
 		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 13:
+	case ALG_DEFLATE:
 		test_deflate();
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 14:
+	case ALG_CAST5:
 		test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
 		test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 15:
+	case ALG_CAST6:
 		test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
 		test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 16:
+	case ALG_ARC4:
 		test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
 		test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 17:
+	case ALG_MICHAEL_MIC:
 		test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 18:
+	case ALG_CRC32C:
 		test_crc32c();
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 19:
+	case ALG_TEA:
 		test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
 		test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 20:
+	case ALG_XTEA:
 		test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
 		test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 21:
+	case ALG_KHAZAD:
 		test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
 		test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 22:
+	case ALG_WP512:
 		test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 23:
+	case ALG_WP384:
 		test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 24:
+	case ALG_WP256:
 		test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 25:
+	case ALG_TNEPRES:
 		test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
 		test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 26:
+	case ALG_ANUBIS:
 		test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
 		test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
 		test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
 		test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 27:
+	case ALG_TGR192:
 		test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
-		break;
-
-	case 28:
+		if (mode_test != ALG_ALL) break;
 
+	case ALG_TGR160:
 		test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
-	case 29:
+	case ALG_TGR128:
 		test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 		
-	case 30:
+	case ALG_XETA:
 		test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
 		test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
-		break;
+		if (mode_test != ALG_ALL) break;
 
+	default:
+		if (mode_test != ALG_ALL)
+			printk("Basic test for '%s' not implemented.\n", name_test);
+		break;
+	}
+	
 #ifdef CONFIG_CRYPTO_HMAC
-	case 100:
+	if (mode_hmac > ALG_NONE)
+	switch (mode_hmac) {
+	case ALG_ALL:
+
+	case ALG_MD5:
 		test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
-		break;
+		if (mode_hmac != ALG_ALL) break;
 
-	case 101:
+	case ALG_SHA1:
 		test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
-		break;
+		if (mode_hmac != ALG_ALL) break;
 
-	case 102:
+	case ALG_SHA256:
 		test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
+		if (mode_hmac != ALG_ALL) break;
+		
+	default:
+		if (mode_hmac != ALG_ALL)
+			printk("HMAC test for '%s' not implemnted.\n", name_hmac);
 		break;
-
+	}
 #endif
 
-	case 200:
+	if (mode_speed > ALG_NONE)
+	switch (mode_speed) {
+	case ALG_ALL:
+
+	case ALG_AES:
 		test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0,
 				  aes_speed_template);
 		test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0,
@@ -1032,9 +1015,9 @@ static void do_test(void)
 				  aes_speed_template);
 		test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0,
 				  aes_speed_template);
-		break;
+		if (mode_speed != ALG_ALL) break;
 
-	case 201:
+	case ALG_DES3_EDE:
 		test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec,
 				  des3_ede_enc_tv_template,
 				  DES3_EDE_ENC_TEST_VECTORS,
@@ -1051,9 +1034,9 @@ static void do_test(void)
 				  des3_ede_dec_tv_template,
 				  DES3_EDE_DEC_TEST_VECTORS,
 				  des3_ede_speed_template);
-		break;
+		if (mode_speed != ALG_ALL) break;
 
-	case 202:
+	case ALG_TWOFISH:
 		test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0,
 				  twofish_speed_template);
 		test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0,
@@ -1062,9 +1045,9 @@ static void do_test(void)
 				  twofish_speed_template);
 		test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0,
 				  twofish_speed_template);
-		break;
+		if (mode_speed != ALG_ALL) break;
 
-	case 203:
+	case ALG_BLOWFISH:
 		test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0,
 				  blowfish_speed_template);
 		test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0,
@@ -1073,9 +1056,9 @@ static void do_test(void)
 				  blowfish_speed_template);
 		test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0,
 				  blowfish_speed_template);
-		break;
+		if (mode_speed != ALG_ALL) break;
 
-	case 204:
+	case ALG_DES:
 		test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0,
 				  des_speed_template);
 		test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0,
@@ -1084,17 +1067,20 @@ static void do_test(void)
 				  des_speed_template);
 		test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0,
 				  des_speed_template);
+		if (mode_speed != ALG_ALL) break;
+
+	default:
+		if (mode_speed != ALG_ALL)
+			printk("Speed test for '%s' not implemented.\n", name_speed);
 		break;
+	}
 
-	case 1000:
+	if (mode_available)
 		test_available();
-		break;
 
-	default:
+	if (mode_test + mode_hmac + mode_speed + mode_available == 0)
 		/* useful for debugging */
 		printk("not testing anything\n");
-		break;
-	}
 }
 
 static int __init init(void)
@@ -1109,6 +1095,11 @@ static int __init init(void)
 		return -ENOMEM;
 	}
 
+	mode_test = name_to_id (name_test);
+	mode_hmac = name_to_id (name_hmac);
+	mode_speed = name_to_id (name_speed);
+	mode_available = name_to_id (name_available);
+
 	do_test();
 
 	kfree(xbuf);
@@ -1125,7 +1116,18 @@ static void __exit fini(void) { }
 module_init(init);
 module_exit(fini);
 
-module_param(mode, int, 0);
+module_param(name_test, charp, 0);
+MODULE_PARM_DESC(name_test, "Algorithm name for basic test mode, or 'all'.");
+
+module_param(name_hmac, charp, 0);
+MODULE_PARM_DESC(name_hmac, "Algorithm name for HMAC test mode, or 'all'.");
+
+module_param(name_speed, charp, 0);
+MODULE_PARM_DESC(name_speed, "Algorithm name for speed test mode, or 'all'.");
+
+module_param(name_available, charp, 0);
+MODULE_PARM_DESC(name_available, "Algorithm name to check for availability, or 'all'.");
+
 module_param(sec, uint, 0);
 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
 		      "(defaults to zero which uses CPU cycles instead)");
Index: linux/crypto/tcrypt.h
===================================================================
--- linux.orig/crypto/tcrypt.h
+++ linux/crypto/tcrypt.h
@@ -25,6 +25,47 @@
 #define MAX_KEYLEN		56
 #define MAX_IVLEN		32
 
+enum alg_ids {
+	ALG_NONE = 0,
+	ALG_ALL = 1,
+	ALG_DES,
+	ALG_MD5,
+	ALG_DES3_EDE,
+	ALG_ROT13,
+	ALG_SHA1,
+	ALG_SHA256,
+	ALG_BLOWFISH,
+	ALG_TWOFISH,
+	ALG_SERPENT,
+	ALG_SHA384,
+	ALG_SHA512,
+	ALG_MD4,
+	ALG_AES,
+	ALG_CAST5,
+	ALG_CAST6,
+	ALG_ARC4,
+	ALG_MICHAEL_MIC,
+	ALG_DEFLATE,
+	ALG_CRC32C,
+	ALG_TEA,
+	ALG_XTEA,
+	ALG_KHAZAD,
+	ALG_WP512,
+	ALG_WP384,
+	ALG_WP256,
+	ALG_TNEPRES,
+	ALG_XETA,
+	ALG_ANUBIS,
+	ALG_TGR192,
+	ALG_TGR160,
+	ALG_TGR128,
+};
+
+struct name_id_map {
+	const char *name;
+	enum alg_ids id;
+};
+
 struct hash_testvec {
 	/* only used with keyed hash algorithms */
 	char key[128] __attribute__ ((__aligned__(4)));

Reply via email to