Lines Matching full:vec
1249 const struct hash_testvec *vec, in build_hash_sglist() argument
1257 kv.iov_base = (void *)vec->plaintext; in build_hash_sglist()
1258 kv.iov_len = vec->psize; in build_hash_sglist()
1259 iov_iter_kvec(&input, ITER_SOURCE, &kv, 1, vec->psize); in build_hash_sglist()
1260 return build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize, in build_hash_sglist()
1266 const struct hash_testvec *vec, in check_hash_result() argument
1271 if (memcmp(result, vec->digest, digestsize) != 0) { in check_hash_result()
1295 static int test_shash_vec_cfg(const struct hash_testvec *vec, in test_shash_vec_cfg() argument
1312 if (vec->ksize) { in test_shash_vec_cfg()
1313 err = do_setkey(crypto_shash_setkey, tfm, vec->key, vec->ksize, in test_shash_vec_cfg()
1316 if (err == vec->setkey_error) in test_shash_vec_cfg()
1319 driver, vec_name, vec->setkey_error, err, in test_shash_vec_cfg()
1323 if (vec->setkey_error) { in test_shash_vec_cfg()
1325 driver, vec_name, vec->setkey_error); in test_shash_vec_cfg()
1331 err = build_hash_sglist(tsgl, vec, cfg, 0, divs); in test_shash_vec_cfg()
1344 vec->digest_error) { in test_shash_vec_cfg()
1355 if (err == vec->digest_error) in test_shash_vec_cfg()
1358 driver, vec_name, vec->digest_error, err, in test_shash_vec_cfg()
1362 if (vec->digest_error) { in test_shash_vec_cfg()
1364 driver, vec_name, vec->digest_error, cfg->name); in test_shash_vec_cfg()
1438 return check_hash_result("shash", result, digestsize, vec, vec_name, in test_shash_vec_cfg()
1478 static int test_ahash_vec_cfg(const struct hash_testvec *vec, in test_ahash_vec_cfg() argument
1499 if (vec->ksize) { in test_ahash_vec_cfg()
1500 err = do_setkey(crypto_ahash_setkey, tfm, vec->key, vec->ksize, in test_ahash_vec_cfg()
1503 if (err == vec->setkey_error) in test_ahash_vec_cfg()
1506 driver, vec_name, vec->setkey_error, err, in test_ahash_vec_cfg()
1510 if (vec->setkey_error) { in test_ahash_vec_cfg()
1512 driver, vec_name, vec->setkey_error); in test_ahash_vec_cfg()
1518 err = build_hash_sglist(tsgl, vec, cfg, 0, divs); in test_ahash_vec_cfg()
1531 vec->digest_error) { in test_ahash_vec_cfg()
1535 ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize); in test_ahash_vec_cfg()
1538 if (err == vec->digest_error) in test_ahash_vec_cfg()
1541 driver, vec_name, vec->digest_error, err, in test_ahash_vec_cfg()
1545 if (vec->digest_error) { in test_ahash_vec_cfg()
1547 driver, vec_name, vec->digest_error, cfg->name); in test_ahash_vec_cfg()
1639 return check_hash_result("ahash", result, digestsize, vec, vec_name, in test_ahash_vec_cfg()
1643 static int test_hash_vec_cfg(const struct hash_testvec *vec, in test_hash_vec_cfg() argument
1660 err = test_shash_vec_cfg(vec, vec_name, cfg, desc, tsgl, in test_hash_vec_cfg()
1666 return test_ahash_vec_cfg(vec, vec_name, cfg, req, tsgl, hashstate); in test_hash_vec_cfg()
1669 static int test_hash_vec(const struct hash_testvec *vec, unsigned int vec_num, in test_hash_vec() argument
1680 err = test_hash_vec_cfg(vec, vec_name, in test_hash_vec()
1698 err = test_hash_vec_cfg(vec, vec_name, &cfg, in test_hash_vec()
1712 * Assumes the buffers in 'vec' were already allocated.
1716 struct hash_testvec *vec, in generate_random_hash_testvec() argument
1722 vec->psize = generate_random_length(rng, maxdatasize); in generate_random_hash_testvec()
1723 generate_random_bytes(rng, (u8 *)vec->plaintext, vec->psize); in generate_random_hash_testvec()
1729 vec->setkey_error = 0; in generate_random_hash_testvec()
1730 vec->ksize = 0; in generate_random_hash_testvec()
1732 vec->ksize = maxkeysize; in generate_random_hash_testvec()
1734 vec->ksize = prandom_u32_inclusive(rng, 1, maxkeysize); in generate_random_hash_testvec()
1735 generate_random_bytes(rng, (u8 *)vec->key, vec->ksize); in generate_random_hash_testvec()
1737 vec->setkey_error = crypto_shash_setkey(desc->tfm, vec->key, in generate_random_hash_testvec()
1738 vec->ksize); in generate_random_hash_testvec()
1740 if (vec->setkey_error) in generate_random_hash_testvec()
1745 vec->digest_error = crypto_shash_digest(desc, vec->plaintext, in generate_random_hash_testvec()
1746 vec->psize, (u8 *)vec->digest); in generate_random_hash_testvec()
1749 vec->psize, vec->ksize); in generate_random_hash_testvec()
1774 struct hash_testvec vec = { 0 }; in test_hash_vs_generic_impl() local
1844 vec.key = kmalloc(maxkeysize, GFP_KERNEL); in test_hash_vs_generic_impl()
1845 vec.plaintext = kmalloc(maxdatasize, GFP_KERNEL); in test_hash_vs_generic_impl()
1846 vec.digest = kmalloc(digestsize, GFP_KERNEL); in test_hash_vs_generic_impl()
1847 if (!vec.key || !vec.plaintext || !vec.digest) { in test_hash_vs_generic_impl()
1853 generate_random_hash_testvec(&rng, generic_desc, &vec, in test_hash_vs_generic_impl()
1859 err = test_hash_vec_cfg(&vec, vec_name, cfg, in test_hash_vs_generic_impl()
1868 kfree(vec.key); in test_hash_vs_generic_impl()
1869 kfree(vec.plaintext); in test_hash_vs_generic_impl()
1870 kfree(vec.digest); in test_hash_vs_generic_impl()
2054 static int test_aead_vec_cfg(int enc, const struct aead_testvec *vec, in test_aead_vec_cfg() argument
2063 const unsigned int authsize = vec->clen - vec->plen; in test_aead_vec_cfg()
2076 if (vec->wk) in test_aead_vec_cfg()
2081 err = do_setkey(crypto_aead_setkey, tfm, vec->key, vec->klen, in test_aead_vec_cfg()
2083 if (err && err != vec->setkey_error) { in test_aead_vec_cfg()
2085 driver, vec_name, vec->setkey_error, err, in test_aead_vec_cfg()
2089 if (!err && vec->setkey_error) { in test_aead_vec_cfg()
2091 driver, vec_name, vec->setkey_error); in test_aead_vec_cfg()
2097 if (err && err != vec->setauthsize_error) { in test_aead_vec_cfg()
2099 driver, vec_name, vec->setauthsize_error, err); in test_aead_vec_cfg()
2102 if (!err && vec->setauthsize_error) { in test_aead_vec_cfg()
2104 driver, vec_name, vec->setauthsize_error); in test_aead_vec_cfg()
2108 if (vec->setkey_error || vec->setauthsize_error) in test_aead_vec_cfg()
2114 if (vec->iv) in test_aead_vec_cfg()
2115 memcpy(iv, vec->iv, ivsize); in test_aead_vec_cfg()
2120 input[0].iov_base = (void *)vec->assoc; in test_aead_vec_cfg()
2121 input[0].iov_len = vec->alen; in test_aead_vec_cfg()
2122 input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext; in test_aead_vec_cfg()
2123 input[1].iov_len = enc ? vec->plen : vec->clen; in test_aead_vec_cfg()
2125 vec->alen + (enc ? vec->plen : in test_aead_vec_cfg()
2126 vec->clen), in test_aead_vec_cfg()
2127 vec->alen + (enc ? vec->clen : in test_aead_vec_cfg()
2128 vec->plen), in test_aead_vec_cfg()
2140 enc ? vec->plen : vec->clen, iv); in test_aead_vec_cfg()
2141 aead_request_set_ad(req, vec->alen); in test_aead_vec_cfg()
2150 if (req->cryptlen != (enc ? vec->plen : vec->clen) || in test_aead_vec_cfg()
2151 req->assoclen != vec->alen || in test_aead_vec_cfg()
2161 if (req->cryptlen != (enc ? vec->plen : vec->clen)) in test_aead_vec_cfg()
2163 if (req->assoclen != vec->alen) in test_aead_vec_cfg()
2194 if ((err == 0 && vec->novrfy) || in test_aead_vec_cfg()
2195 (err != vec->crypt_error && !(err == -EBADMSG && vec->novrfy))) { in test_aead_vec_cfg()
2198 if (vec->novrfy && in test_aead_vec_cfg()
2199 vec->crypt_error != 0 && vec->crypt_error != -EBADMSG) in test_aead_vec_cfg()
2201 vec->crypt_error); in test_aead_vec_cfg()
2202 else if (vec->novrfy) in test_aead_vec_cfg()
2205 sprintf(expected_error, "%d", vec->crypt_error); in test_aead_vec_cfg()
2220 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, in test_aead_vec_cfg()
2221 enc ? vec->clen : vec->plen, in test_aead_vec_cfg()
2222 vec->alen, in test_aead_vec_cfg()
2238 static int test_aead_vec(int enc, const struct aead_testvec *vec, in test_aead_vec() argument
2246 if (enc && vec->novrfy) in test_aead_vec()
2252 err = test_aead_vec_cfg(enc, vec, vec_name, in test_aead_vec()
2270 err = test_aead_vec_cfg(enc, vec, vec_name, in test_aead_vec()
2292 struct aead_testvec vec; member
2304 struct aead_testvec *vec, bool aad_iv, in mutate_aead_message() argument
2308 const unsigned int authsize = vec->clen - vec->plen; in mutate_aead_message()
2310 if (prandom_bool(rng) && vec->alen > aad_tail_size) { in mutate_aead_message()
2312 flip_random_bit(rng, (u8 *)vec->assoc, in mutate_aead_message()
2313 vec->alen - aad_tail_size); in mutate_aead_message()
2319 flip_random_bit(rng, (u8 *)vec->ctext + vec->plen, authsize); in mutate_aead_message()
2322 flip_random_bit(rng, (u8 *)vec->ctext, vec->clen); in mutate_aead_message()
2336 struct aead_testvec *vec, in generate_aead_message() argument
2341 const unsigned int authsize = vec->clen - vec->plen; in generate_aead_message()
2347 generate_random_bytes(rng, (u8 *)vec->assoc, vec->alen); in generate_aead_message()
2348 if (suite->aad_iv && vec->alen >= ivsize) in generate_aead_message()
2350 memcpy((u8 *)vec->assoc + vec->alen - ivsize, vec->iv, ivsize); in generate_aead_message()
2354 generate_random_bytes(rng, (u8 *)vec->ctext, vec->clen); in generate_aead_message()
2363 if (vec->alen) in generate_aead_message()
2364 sg_set_buf(&src[i++], vec->assoc, vec->alen); in generate_aead_message()
2365 if (vec->plen) { in generate_aead_message()
2366 generate_random_bytes(rng, (u8 *)vec->ptext, vec->plen); in generate_aead_message()
2367 sg_set_buf(&src[i++], vec->ptext, vec->plen); in generate_aead_message()
2369 sg_init_one(&dst, vec->ctext, vec->alen + vec->clen); in generate_aead_message()
2370 memcpy(iv, vec->iv, ivsize); in generate_aead_message()
2372 aead_request_set_crypt(req, src, &dst, vec->plen, iv); in generate_aead_message()
2373 aead_request_set_ad(req, vec->alen); in generate_aead_message()
2374 vec->crypt_error = crypto_wait_req(crypto_aead_encrypt(req), in generate_aead_message()
2377 if (vec->crypt_error != 0) in generate_aead_message()
2379 memmove((u8 *)vec->ctext, vec->ctext + vec->alen, vec->clen); in generate_aead_message()
2386 mutate_aead_message(rng, vec, suite->aad_iv, ivsize); in generate_aead_message()
2388 vec->novrfy = 1; in generate_aead_message()
2390 vec->crypt_error = -EINVAL; in generate_aead_message()
2394 * Generate an AEAD test vector 'vec' using the implementation specified by
2395 * 'req'. The buffers in 'vec' must already be allocated.
2398 * test vectors (i.e. vectors with 'vec->novrfy=1') more often.
2402 struct aead_testvec *vec, in generate_random_aead_testvec() argument
2416 vec->klen = maxkeysize; in generate_random_aead_testvec()
2418 vec->klen = prandom_u32_below(rng, maxkeysize + 1); in generate_random_aead_testvec()
2419 generate_random_bytes(rng, (u8 *)vec->key, vec->klen); in generate_random_aead_testvec()
2420 vec->setkey_error = crypto_aead_setkey(tfm, vec->key, vec->klen); in generate_random_aead_testvec()
2423 generate_random_bytes(rng, (u8 *)vec->iv, ivsize); in generate_random_aead_testvec()
2434 vec->setauthsize_error = crypto_aead_setauthsize(tfm, authsize); in generate_random_aead_testvec()
2439 vec->alen = 0; in generate_random_aead_testvec()
2441 vec->alen = generate_random_length(rng, total_len); in generate_random_aead_testvec()
2442 vec->plen = total_len - vec->alen; in generate_random_aead_testvec()
2443 vec->clen = vec->plen + authsize; in generate_random_aead_testvec()
2449 vec->novrfy = 0; in generate_random_aead_testvec()
2450 vec->crypt_error = 0; in generate_random_aead_testvec()
2451 if (vec->setkey_error == 0 && vec->setauthsize_error == 0) in generate_random_aead_testvec()
2452 generate_aead_message(rng, req, suite, vec, prefer_inauthentic); in generate_random_aead_testvec()
2455 vec->alen, vec->plen, authsize, vec->klen, vec->novrfy); in generate_random_aead_testvec()
2464 generate_random_aead_testvec(&ctx->rng, ctx->req, &ctx->vec, in try_to_generate_inauthentic_testvec()
2469 if (ctx->vec.novrfy) in try_to_generate_inauthentic_testvec()
2487 * test vectors other than inauthentic ones (vec.novrfy=1) here. in test_aead_inauthentic_inputs()
2494 if (ctx->vec.novrfy) { in test_aead_inauthentic_inputs()
2498 err = test_aead_vec_cfg(DECRYPT, &ctx->vec, in test_aead_inauthentic_inputs()
2586 generate_random_aead_testvec(&ctx->rng, generic_req, &ctx->vec, in test_aead_vs_generic_impl()
2594 if (!ctx->vec.novrfy) { in test_aead_vs_generic_impl()
2595 err = test_aead_vec_cfg(ENCRYPT, &ctx->vec, in test_aead_vs_generic_impl()
2601 if (ctx->vec.crypt_error == 0 || ctx->vec.novrfy) { in test_aead_vs_generic_impl()
2602 err = test_aead_vec_cfg(DECRYPT, &ctx->vec, in test_aead_vs_generic_impl()
2642 ctx->vec.key = kmalloc(ctx->maxkeysize, GFP_KERNEL); in test_aead_extra()
2643 ctx->vec.iv = kmalloc(crypto_aead_ivsize(ctx->tfm), GFP_KERNEL); in test_aead_extra()
2644 ctx->vec.assoc = kmalloc(ctx->maxdatasize, GFP_KERNEL); in test_aead_extra()
2645 ctx->vec.ptext = kmalloc(ctx->maxdatasize, GFP_KERNEL); in test_aead_extra()
2646 ctx->vec.ctext = kmalloc(ctx->maxdatasize, GFP_KERNEL); in test_aead_extra()
2647 if (!ctx->vec.key || !ctx->vec.iv || !ctx->vec.assoc || in test_aead_extra()
2648 !ctx->vec.ptext || !ctx->vec.ctext) { in test_aead_extra()
2659 kfree(ctx->vec.key); in test_aead_extra()
2660 kfree(ctx->vec.iv); in test_aead_extra()
2661 kfree(ctx->vec.assoc); in test_aead_extra()
2662 kfree(ctx->vec.ptext); in test_aead_extra()
2663 kfree(ctx->vec.ctext); in test_aead_extra()
2835 static int test_skcipher_vec_cfg(int enc, const struct cipher_testvec *vec, in test_skcipher_vec_cfg() argument
2856 if (vec->wk) in test_skcipher_vec_cfg()
2861 err = do_setkey(crypto_skcipher_setkey, tfm, vec->key, vec->klen, in test_skcipher_vec_cfg()
2864 if (err == vec->setkey_error) in test_skcipher_vec_cfg()
2867 driver, vec_name, vec->setkey_error, err, in test_skcipher_vec_cfg()
2871 if (vec->setkey_error) { in test_skcipher_vec_cfg()
2873 driver, vec_name, vec->setkey_error); in test_skcipher_vec_cfg()
2881 if (vec->generates_iv && !enc) in test_skcipher_vec_cfg()
2882 memcpy(iv, vec->iv_out, ivsize); in test_skcipher_vec_cfg()
2883 else if (vec->iv) in test_skcipher_vec_cfg()
2884 memcpy(iv, vec->iv, ivsize); in test_skcipher_vec_cfg()
2888 if (vec->generates_iv) { in test_skcipher_vec_cfg()
2897 input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext; in test_skcipher_vec_cfg()
2898 input.iov_len = vec->len; in test_skcipher_vec_cfg()
2900 vec->len, vec->len, &input, 1); in test_skcipher_vec_cfg()
2911 vec->len, iv); in test_skcipher_vec_cfg()
2920 if (req->cryptlen != vec->len || in test_skcipher_vec_cfg()
2930 if (req->cryptlen != vec->len) in test_skcipher_vec_cfg()
2962 if (err == vec->crypt_error) in test_skcipher_vec_cfg()
2965 driver, op, vec_name, vec->crypt_error, err, cfg->name); in test_skcipher_vec_cfg()
2968 if (vec->crypt_error) { in test_skcipher_vec_cfg()
2970 driver, op, vec_name, vec->crypt_error, cfg->name); in test_skcipher_vec_cfg()
2975 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, in test_skcipher_vec_cfg()
2976 vec->len, 0, true); in test_skcipher_vec_cfg()
2989 if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) { in test_skcipher_vec_cfg()
2999 static int test_skcipher_vec(int enc, const struct cipher_testvec *vec, in test_skcipher_vec() argument
3008 if (fips_enabled && vec->fips_skip) in test_skcipher_vec()
3014 err = test_skcipher_vec_cfg(enc, vec, vec_name, in test_skcipher_vec()
3032 err = test_skcipher_vec_cfg(enc, vec, vec_name, in test_skcipher_vec()
3046 * Assumes the buffers in 'vec' were already allocated.
3050 struct cipher_testvec *vec, in generate_random_cipher_testvec() argument
3062 vec->klen = maxkeysize; in generate_random_cipher_testvec()
3064 vec->klen = prandom_u32_below(rng, maxkeysize + 1); in generate_random_cipher_testvec()
3065 generate_random_bytes(rng, (u8 *)vec->key, vec->klen); in generate_random_cipher_testvec()
3066 vec->setkey_error = crypto_skcipher_setkey(tfm, vec->key, vec->klen); in generate_random_cipher_testvec()
3069 generate_random_bytes(rng, (u8 *)vec->iv, ivsize); in generate_random_cipher_testvec()
3072 vec->len = generate_random_length(rng, maxdatasize); in generate_random_cipher_testvec()
3073 generate_random_bytes(rng, (u8 *)vec->ptext, vec->len); in generate_random_cipher_testvec()
3076 if (vec->setkey_error) in generate_random_cipher_testvec()
3080 sg_init_one(&src, vec->ptext, vec->len); in generate_random_cipher_testvec()
3081 sg_init_one(&dst, vec->ctext, vec->len); in generate_random_cipher_testvec()
3082 memcpy(iv, vec->iv, ivsize); in generate_random_cipher_testvec()
3084 skcipher_request_set_crypt(req, &src, &dst, vec->len, iv); in generate_random_cipher_testvec()
3085 vec->crypt_error = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); in generate_random_cipher_testvec()
3086 if (vec->crypt_error != 0) { in generate_random_cipher_testvec()
3093 memset((u8 *)vec->ctext, 0, vec->len); in generate_random_cipher_testvec()
3097 vec->len, vec->klen); in generate_random_cipher_testvec()
3120 struct cipher_testvec vec = { 0 }; in test_skcipher_vs_generic_impl() local
3209 vec.key = kmalloc(maxkeysize, GFP_KERNEL); in test_skcipher_vs_generic_impl()
3210 vec.iv = kmalloc(ivsize, GFP_KERNEL); in test_skcipher_vs_generic_impl()
3211 vec.ptext = kmalloc(maxdatasize, GFP_KERNEL); in test_skcipher_vs_generic_impl()
3212 vec.ctext = kmalloc(maxdatasize, GFP_KERNEL); in test_skcipher_vs_generic_impl()
3213 if (!vec.key || !vec.iv || !vec.ptext || !vec.ctext) { in test_skcipher_vs_generic_impl()
3219 generate_random_cipher_testvec(&rng, generic_req, &vec, in test_skcipher_vs_generic_impl()
3225 err = test_skcipher_vec_cfg(ENCRYPT, &vec, vec_name, in test_skcipher_vs_generic_impl()
3229 err = test_skcipher_vec_cfg(DECRYPT, &vec, vec_name, in test_skcipher_vs_generic_impl()
3238 kfree(vec.key); in test_skcipher_vs_generic_impl()
3239 kfree(vec.iv); in test_skcipher_vs_generic_impl()
3240 kfree(vec.ptext); in test_skcipher_vs_generic_impl()
3241 kfree(vec.ctext); in test_skcipher_vs_generic_impl()
3930 static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, in do_test_kpp() argument
3950 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size); in do_test_kpp()
3976 if (vec->genkey) { in do_test_kpp()
3985 if (memcmp(vec->expected_a_public, sg_virt(req->dst), in do_test_kpp()
3986 vec->expected_a_public_size)) { in do_test_kpp()
3995 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL); in do_test_kpp()
4001 sg_init_one(&src, input_buf, vec->b_public_size); in do_test_kpp()
4003 kpp_request_set_input(req, &src, vec->b_public_size); in do_test_kpp()
4014 if (vec->genkey) { in do_test_kpp()
4016 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL); in do_test_kpp()
4026 err = crypto_kpp_set_secret(tfm, vec->b_secret, in do_test_kpp()
4027 vec->b_secret_size); in do_test_kpp()
4031 sg_init_one(&src, a_public, vec->expected_a_public_size); in do_test_kpp()
4033 kpp_request_set_input(req, &src, vec->expected_a_public_size); in do_test_kpp()
4047 shared_secret = (void *)vec->expected_ss; in do_test_kpp()
4055 vec->expected_ss_size)) { in do_test_kpp()