diff options
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r-- | crypto/testmgr.c | 403 |
1 files changed, 383 insertions, 20 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 6d5b746637b..deacec764fb 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -115,6 +115,7 @@ static void hexdump(unsigned char *buf, unsigned int len) buf, len, false); } + static void tcrypt_complete(struct crypto_async_request *req, int err) { struct tcrypt_result *res = req->data; @@ -169,6 +170,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, if (testmgr_alloc_buf(xbuf)) goto out_nobuf; + init_completion(&tresult.completion); req = ahash_request_alloc(tfm, GFP_KERNEL); @@ -338,6 +340,7 @@ static int test_aead(struct crypto_aead *tfm, int enc, goto out_noxbuf; if (testmgr_alloc_buf(axbuf)) goto out_noaxbuf; + if (enc == ENCRYPT) e = "encryption"; @@ -373,6 +376,7 @@ static int test_aead(struct crypto_aead *tfm, int enc, memcpy(input, template[i].input, template[i].ilen); memcpy(assoc, template[i].assoc, template[i].alen); + if (template[i].iv) memcpy(iv, template[i].iv, MAX_IVLEN); else @@ -384,17 +388,10 @@ static int test_aead(struct crypto_aead *tfm, int enc, tfm, CRYPTO_TFM_REQ_WEAK_KEY); key = template[i].key; - ret = crypto_aead_setkey(tfm, key, template[i].klen); - if (!ret == template[i].fail) { - printk(KERN_ERR "alg: aead: setkey failed on " - "test %d for %s: flags=%x\n", j, algo, - crypto_aead_get_flags(tfm)); - goto out; - } else if (ret) + if (ret) continue; - authsize = abs(template[i].rlen - template[i].ilen); ret = crypto_aead_setauthsize(tfm, authsize); if (ret) { @@ -404,9 +401,9 @@ static int test_aead(struct crypto_aead *tfm, int enc, goto out; } + sg_init_one(&sg[0], input, template[i].ilen + (enc ? authsize : 0)); - sg_init_one(&asg[0], assoc, template[i].alen); aead_request_set_crypt(req, sg, sg, @@ -447,6 +444,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, default: printk(KERN_ERR "alg: aead: %s failed on test " "%d for %s: ret=%d\n", e, j, algo, -ret); + q = input; + hexdump(q, template[i].rlen); goto out; } @@ -456,6 +455,7 @@ static int test_aead(struct crypto_aead *tfm, int enc, "%s for %s\n", j, e, algo); hexdump(q, template[i].rlen); ret = -EINVAL; + //ret = 0; goto out; } } @@ -656,6 +656,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc, if (testmgr_alloc_buf(xbuf)) goto out_nobuf; + if (enc == ENCRYPT) e = "encryption"; else @@ -714,6 +715,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc, out: testmgr_free_buf(xbuf); out_nobuf: + return ret; } @@ -724,7 +726,7 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); unsigned int i, j, k, n, temp; char *q; - struct ablkcipher_request *req; + struct ablkcipher_request *req = NULL; struct scatterlist sg[8]; const char *e; struct tcrypt_result result; @@ -743,6 +745,7 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, init_completion(&result.completion); + //printk("Testing %s algo = %s\n", algo); req = ablkcipher_request_alloc(tfm, GFP_KERNEL); if (!req) { printk(KERN_ERR "alg: skcipher: Failed to allocate request " @@ -1274,8 +1277,10 @@ static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, if (desc->suite.aead.enc.vecs) { err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs, desc->suite.aead.enc.count); +#if 1 if (err) goto out; +#endif } if (!err && desc->suite.aead.dec.vecs) @@ -1329,6 +1334,7 @@ static int alg_test_skcipher(const struct alg_test_desc *desc, return PTR_ERR(tfm); } + //printk("in alg_test_skcipher driver name = %s\n", driver); if (desc->suite.cipher.enc.vecs) { err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, desc->suite.cipher.enc.count); @@ -1477,6 +1483,344 @@ static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver, return err; } +/* This definitions are for those algs which could not be tested by + * linux testmgr module but since we have exclusive test vectors for them, + * adding them separetly + */ +static const struct alg_test_desc alg_test_descs_k[] = { + { + .alg = "f8(kasumi)", + .test = alg_test_skcipher, + .suite = { + .cipher = { + .enc = { + .vecs = kasumi_f8_enc_template, + .count = 1 + }, + .dec = { + .vecs = kasumi_dec_template, + .count = 1 + } + } + } + }, + { + .alg = "ssl(aes-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = ssl_aes_128_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = ssl_aes_128_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "ssl(des-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = ssl_des_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = ssl_des_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + + { + .alg = "ssl(arc4-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = ssl_arc4_sha1_enc_tv_template, + .count = 1 + }, + + .dec = { + .vecs = ssl_arc4_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "ssl(NULL-md5)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = ssl_null_md5_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = ssl_null_md5_dec_tv_template, + .count = 1 + } + + } + } + }, + /* Currently disabled all the DTLS testing since, + * the DTLS enc test cases fail due to Random IV generation + */ +#if 0 + { + .alg = "dtls(aes-sha1)", + .test = alg_test_aead, + .suite = { + .aead = + { + .enc = { + .vecs = dtls_aes_128_sha1_enc_tv_template, + .count = 1 + }, + + .dec = { + .vecs = dtls_aes_128_sha1_dec_tv_template, + .count = 0 + } + } + } + }, + { + .alg = "dtls(des3-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = dtls_3des_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = dtls_3des_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "dtls(NULL-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = dtls_null_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = dtls_null_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "dtls(NULL-md5)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = dtls_null_md5_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = dtls_null_md5_dec_tv_template, + .count = 1 + } + + } + } + }, +#endif + { + .alg = "tls(aes-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls_aes_128_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls_aes_128_sha1_dec_tv_template, + .count = 1 + } + } + } + }, + { + .alg = "tls(des-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls_des_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls_des_sha1_dec_tv_template, + .count = 1 + } + } + } + }, + { + .alg = "tls(des3-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls_3des_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls_3des_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "tls(arc4-md5)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls_arc4_md5_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls_arc4_md5_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "tls1_1(aes-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls1v1_aes_128_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls1v1_aes_128_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + + { + .alg = "tls1_1(des-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls1v1_des_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls1v1_des_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, +#if 1 + { + .alg = "tls1_1(des3-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls1v1_3des_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls1v1_3des_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "tls1_1(arc4-md5)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls1v1_arc4_md5_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls1v1_arc4_md5_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "tls1_1(arc4-sha1)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls1v1_arc4_sha1_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls1v1_arc4_sha1_dec_tv_template, + .count = 1 + } + + } + } + }, + { + .alg = "tls1_1(NULL-md5)", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = tls1v1_null_md5_enc_tv_template, + .count = 1 + }, + .dec = { + .vecs = tls1v1_null_md5_dec_tv_template, + .count = 1 + } + + } + } + }, +#endif +}; + /* Please keep this list sorted by algorithm name. */ static const struct alg_test_desc alg_test_descs[] = { { @@ -1596,7 +1940,8 @@ static const struct alg_test_desc alg_test_descs[] = { } } } - }, { + }, + { .alg = "ccm(aes)", .test = alg_test_aead, .fips_allowed = 1, @@ -1612,7 +1957,8 @@ static const struct alg_test_desc alg_test_descs[] = { } } } - }, { + }, +{ .alg = "crc32c", .test = alg_test_crc32c, .fips_allowed = 1, @@ -1926,7 +2272,8 @@ static const struct alg_test_desc alg_test_descs[] = { } } } - }, { + }, + { .alg = "gcm(aes)", .test = alg_test_aead, .fips_allowed = 1, @@ -1942,7 +2289,7 @@ static const struct alg_test_desc alg_test_descs[] = { } } } - }, { + },{ .alg = "hmac(md5)", .test = alg_test_hash, .suite = { @@ -1979,7 +2326,8 @@ static const struct alg_test_desc alg_test_descs[] = { .count = HMAC_SHA1_TEST_VECTORS } } - }, { + }, + { .alg = "hmac(sha224)", .test = alg_test_hash, .fips_allowed = 1, @@ -1989,7 +2337,8 @@ static const struct alg_test_desc alg_test_descs[] = { .count = HMAC_SHA224_TEST_VECTORS } } - }, { + }, + { .alg = "hmac(sha256)", .test = alg_test_hash, .fips_allowed = 1, @@ -2019,7 +2368,8 @@ static const struct alg_test_desc alg_test_descs[] = { .count = HMAC_SHA512_TEST_VECTORS } } - }, { + }, +{ .alg = "lrw(aes)", .test = alg_test_skcipher, .suite = { @@ -2283,7 +2633,8 @@ static const struct alg_test_desc alg_test_descs[] = { .count = WP512_TEST_VECTORS } } - }, { + }, + { .alg = "xcbc(aes)", .test = alg_test_hash, .suite = { @@ -2292,7 +2643,8 @@ static const struct alg_test_desc alg_test_descs[] = { .count = XCBC_AES_TEST_VECTORS } } - }, { + }, +{ .alg = "xts(aes)", .test = alg_test_skcipher, .suite = { @@ -2330,6 +2682,7 @@ static int alg_find_test(const char *alg) int start = 0; int end = ARRAY_SIZE(alg_test_descs); + //printk("comparing alg = %s\n", alg); while (start < end) { int i = (start + end) / 2; int diff = strcmp(alg_test_descs[i].alg, alg); @@ -2374,6 +2727,16 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask) goto test_done; } + /* Enable these if want to test DTLS, SSL, TLS and TLSV11 and Kasumi */ +#if 1 + for ( i = 0; i < 15; i++) { + if (strcmp(alg, alg_test_descs_k[i].alg) == 0) { + rc = alg_test_descs_k[i].test(alg_test_descs_k + i, driver, + type, mask); + return rc; + } + } +#endif i = alg_find_test(alg); j = alg_find_test(driver); if (i < 0 && j < 0) @@ -2402,7 +2765,7 @@ test_done: return rc; notest: - printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); + //printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); return 0; non_fips_alg: return -EINVAL; |