162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2022 Oracle and/or its affiliates.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * KUnit test of SunRPC's GSS Kerberos mechanism. Subsystem
662306a36Sopenharmony_ci * name is "rpcsec_gss_krb5".
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <kunit/test.h>
1062306a36Sopenharmony_ci#include <kunit/visibility.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/kernel.h>
1362306a36Sopenharmony_ci#include <crypto/hash.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <linux/sunrpc/xdr.h>
1662306a36Sopenharmony_ci#include <linux/sunrpc/gss_krb5.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include "gss_krb5_internal.h"
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ciMODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct gss_krb5_test_param {
2362306a36Sopenharmony_ci	const char			*desc;
2462306a36Sopenharmony_ci	u32				enctype;
2562306a36Sopenharmony_ci	u32				nfold;
2662306a36Sopenharmony_ci	u32				constant;
2762306a36Sopenharmony_ci	const struct xdr_netobj		*base_key;
2862306a36Sopenharmony_ci	const struct xdr_netobj		*Ke;
2962306a36Sopenharmony_ci	const struct xdr_netobj		*usage;
3062306a36Sopenharmony_ci	const struct xdr_netobj		*plaintext;
3162306a36Sopenharmony_ci	const struct xdr_netobj		*confounder;
3262306a36Sopenharmony_ci	const struct xdr_netobj		*expected_result;
3362306a36Sopenharmony_ci	const struct xdr_netobj		*expected_hmac;
3462306a36Sopenharmony_ci	const struct xdr_netobj		*next_iv;
3562306a36Sopenharmony_ci};
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistatic inline void gss_krb5_get_desc(const struct gss_krb5_test_param *param,
3862306a36Sopenharmony_ci				     char *desc)
3962306a36Sopenharmony_ci{
4062306a36Sopenharmony_ci	strscpy(desc, param->desc, KUNIT_PARAM_DESC_SIZE);
4162306a36Sopenharmony_ci}
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_cistatic void kdf_case(struct kunit *test)
4462306a36Sopenharmony_ci{
4562306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
4662306a36Sopenharmony_ci	const struct gss_krb5_enctype *gk5e;
4762306a36Sopenharmony_ci	struct xdr_netobj derivedkey;
4862306a36Sopenharmony_ci	int err;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci	/* Arrange */
5162306a36Sopenharmony_ci	gk5e = gss_krb5_lookup_enctype(param->enctype);
5262306a36Sopenharmony_ci	if (!gk5e)
5362306a36Sopenharmony_ci		kunit_skip(test, "Encryption type is not available");
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	derivedkey.data = kunit_kzalloc(test, param->expected_result->len,
5662306a36Sopenharmony_ci					GFP_KERNEL);
5762306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, derivedkey.data);
5862306a36Sopenharmony_ci	derivedkey.len = param->expected_result->len;
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	/* Act */
6162306a36Sopenharmony_ci	err = gk5e->derive_key(gk5e, param->base_key, &derivedkey,
6262306a36Sopenharmony_ci			       param->usage, GFP_KERNEL);
6362306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	/* Assert */
6662306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
6762306a36Sopenharmony_ci			    memcmp(param->expected_result->data,
6862306a36Sopenharmony_ci				   derivedkey.data, derivedkey.len), 0,
6962306a36Sopenharmony_ci			    "key mismatch");
7062306a36Sopenharmony_ci}
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_cistatic void checksum_case(struct kunit *test)
7362306a36Sopenharmony_ci{
7462306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
7562306a36Sopenharmony_ci	struct xdr_buf buf = {
7662306a36Sopenharmony_ci		.head[0].iov_len	= param->plaintext->len,
7762306a36Sopenharmony_ci		.len			= param->plaintext->len,
7862306a36Sopenharmony_ci	};
7962306a36Sopenharmony_ci	const struct gss_krb5_enctype *gk5e;
8062306a36Sopenharmony_ci	struct xdr_netobj Kc, checksum;
8162306a36Sopenharmony_ci	struct crypto_ahash *tfm;
8262306a36Sopenharmony_ci	int err;
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	/* Arrange */
8562306a36Sopenharmony_ci	gk5e = gss_krb5_lookup_enctype(param->enctype);
8662306a36Sopenharmony_ci	if (!gk5e)
8762306a36Sopenharmony_ci		kunit_skip(test, "Encryption type is not available");
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci	Kc.len = gk5e->Kc_length;
9062306a36Sopenharmony_ci	Kc.data = kunit_kzalloc(test, Kc.len, GFP_KERNEL);
9162306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Kc.data);
9262306a36Sopenharmony_ci	err = gk5e->derive_key(gk5e, param->base_key, &Kc,
9362306a36Sopenharmony_ci			       param->usage, GFP_KERNEL);
9462306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci	tfm = crypto_alloc_ahash(gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
9762306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, tfm);
9862306a36Sopenharmony_ci	err = crypto_ahash_setkey(tfm, Kc.data, Kc.len);
9962306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci	buf.head[0].iov_base = kunit_kzalloc(test, buf.head[0].iov_len, GFP_KERNEL);
10262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf.head[0].iov_base);
10362306a36Sopenharmony_ci	memcpy(buf.head[0].iov_base, param->plaintext->data, buf.head[0].iov_len);
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	checksum.len = gk5e->cksumlength;
10662306a36Sopenharmony_ci	checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
10762306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	/* Act */
11062306a36Sopenharmony_ci	err = gss_krb5_checksum(tfm, NULL, 0, &buf, 0, &checksum);
11162306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	/* Assert */
11462306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
11562306a36Sopenharmony_ci			    memcmp(param->expected_result->data,
11662306a36Sopenharmony_ci				   checksum.data, checksum.len), 0,
11762306a36Sopenharmony_ci			    "checksum mismatch");
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci	crypto_free_ahash(tfm);
12062306a36Sopenharmony_ci}
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#define DEFINE_HEX_XDR_NETOBJ(name, hex_array...)		\
12362306a36Sopenharmony_ci	static const u8 name ## _data[] = { hex_array };	\
12462306a36Sopenharmony_ci	static const struct xdr_netobj name = {			\
12562306a36Sopenharmony_ci		.data	= (u8 *)name##_data,			\
12662306a36Sopenharmony_ci		.len	= sizeof(name##_data),			\
12762306a36Sopenharmony_ci	}
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci#define DEFINE_STR_XDR_NETOBJ(name, string)			\
13062306a36Sopenharmony_ci	static const u8 name ## _str[] = string;		\
13162306a36Sopenharmony_ci	static const struct xdr_netobj name = {			\
13262306a36Sopenharmony_ci		.data	= (u8 *)name##_str,			\
13362306a36Sopenharmony_ci		.len	= sizeof(name##_str) - 1,		\
13462306a36Sopenharmony_ci	}
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/*
13762306a36Sopenharmony_ci * RFC 3961 Appendix A.1.  n-fold
13862306a36Sopenharmony_ci *
13962306a36Sopenharmony_ci * The n-fold function is defined in section 5.1 of RFC 3961.
14062306a36Sopenharmony_ci *
14162306a36Sopenharmony_ci * This test material is copyright (C) The Internet Society (2005).
14262306a36Sopenharmony_ci */
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test1_plaintext,
14562306a36Sopenharmony_ci		      0x30, 0x31, 0x32, 0x33, 0x34, 0x35
14662306a36Sopenharmony_ci);
14762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test1_expected_result,
14862306a36Sopenharmony_ci		      0xbe, 0x07, 0x26, 0x31, 0x27, 0x6b, 0x19, 0x55
14962306a36Sopenharmony_ci);
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test2_plaintext,
15262306a36Sopenharmony_ci		      0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
15362306a36Sopenharmony_ci);
15462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test2_expected_result,
15562306a36Sopenharmony_ci		      0x78, 0xa0, 0x7b, 0x6c, 0xaf, 0x85, 0xfa
15662306a36Sopenharmony_ci);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test3_plaintext,
15962306a36Sopenharmony_ci		      0x52, 0x6f, 0x75, 0x67, 0x68, 0x20, 0x43, 0x6f,
16062306a36Sopenharmony_ci		      0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2c,
16162306a36Sopenharmony_ci		      0x20, 0x61, 0x6e, 0x64, 0x20, 0x52, 0x75, 0x6e,
16262306a36Sopenharmony_ci		      0x6e, 0x69, 0x6e, 0x67, 0x20, 0x43, 0x6f, 0x64,
16362306a36Sopenharmony_ci		      0x65
16462306a36Sopenharmony_ci);
16562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test3_expected_result,
16662306a36Sopenharmony_ci		      0xbb, 0x6e, 0xd3, 0x08, 0x70, 0xb7, 0xf0, 0xe0
16762306a36Sopenharmony_ci);
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test4_plaintext,
17062306a36Sopenharmony_ci		      0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
17162306a36Sopenharmony_ci);
17262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test4_expected_result,
17362306a36Sopenharmony_ci		      0x59, 0xe4, 0xa8, 0xca, 0x7c, 0x03, 0x85, 0xc3,
17462306a36Sopenharmony_ci		      0xc3, 0x7b, 0x3f, 0x6d, 0x20, 0x00, 0x24, 0x7c,
17562306a36Sopenharmony_ci		      0xb6, 0xe6, 0xbd, 0x5b, 0x3e
17662306a36Sopenharmony_ci);
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test5_plaintext,
17962306a36Sopenharmony_ci		      0x4d, 0x41, 0x53, 0x53, 0x41, 0x43, 0x48, 0x56,
18062306a36Sopenharmony_ci		      0x53, 0x45, 0x54, 0x54, 0x53, 0x20, 0x49, 0x4e,
18162306a36Sopenharmony_ci		      0x53, 0x54, 0x49, 0x54, 0x56, 0x54, 0x45, 0x20,
18262306a36Sopenharmony_ci		      0x4f, 0x46, 0x20, 0x54, 0x45, 0x43, 0x48, 0x4e,
18362306a36Sopenharmony_ci		      0x4f, 0x4c, 0x4f, 0x47, 0x59
18462306a36Sopenharmony_ci);
18562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test5_expected_result,
18662306a36Sopenharmony_ci		      0xdb, 0x3b, 0x0d, 0x8f, 0x0b, 0x06, 0x1e, 0x60,
18762306a36Sopenharmony_ci		      0x32, 0x82, 0xb3, 0x08, 0xa5, 0x08, 0x41, 0x22,
18862306a36Sopenharmony_ci		      0x9a, 0xd7, 0x98, 0xfa, 0xb9, 0x54, 0x0c, 0x1b
18962306a36Sopenharmony_ci);
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test6_plaintext,
19262306a36Sopenharmony_ci		      0x51
19362306a36Sopenharmony_ci);
19462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test6_expected_result,
19562306a36Sopenharmony_ci		      0x51, 0x8a, 0x54, 0xa2, 0x15, 0xa8, 0x45, 0x2a,
19662306a36Sopenharmony_ci		      0x51, 0x8a, 0x54, 0xa2, 0x15, 0xa8, 0x45, 0x2a,
19762306a36Sopenharmony_ci		      0x51, 0x8a, 0x54, 0xa2, 0x15
19862306a36Sopenharmony_ci);
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test7_plaintext,
20162306a36Sopenharmony_ci		      0x62, 0x61
20262306a36Sopenharmony_ci);
20362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test7_expected_result,
20462306a36Sopenharmony_ci		      0xfb, 0x25, 0xd5, 0x31, 0xae, 0x89, 0x74, 0x49,
20562306a36Sopenharmony_ci		      0x9f, 0x52, 0xfd, 0x92, 0xea, 0x98, 0x57, 0xc4,
20662306a36Sopenharmony_ci		      0xba, 0x24, 0xcf, 0x29, 0x7e
20762306a36Sopenharmony_ci);
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test_kerberos,
21062306a36Sopenharmony_ci		      0x6b, 0x65, 0x72, 0x62, 0x65, 0x72, 0x6f, 0x73
21162306a36Sopenharmony_ci);
21262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test8_expected_result,
21362306a36Sopenharmony_ci		      0x6b, 0x65, 0x72, 0x62, 0x65, 0x72, 0x6f, 0x73
21462306a36Sopenharmony_ci);
21562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test9_expected_result,
21662306a36Sopenharmony_ci		      0x6b, 0x65, 0x72, 0x62, 0x65, 0x72, 0x6f, 0x73,
21762306a36Sopenharmony_ci		      0x7b, 0x9b, 0x5b, 0x2b, 0x93, 0x13, 0x2b, 0x93
21862306a36Sopenharmony_ci);
21962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test10_expected_result,
22062306a36Sopenharmony_ci		      0x83, 0x72, 0xc2, 0x36, 0x34, 0x4e, 0x5f, 0x15,
22162306a36Sopenharmony_ci		      0x50, 0xcd, 0x07, 0x47, 0xe1, 0x5d, 0x62, 0xca,
22262306a36Sopenharmony_ci		      0x7a, 0x5a, 0x3b, 0xce, 0xa4
22362306a36Sopenharmony_ci);
22462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(nfold_test11_expected_result,
22562306a36Sopenharmony_ci		      0x6b, 0x65, 0x72, 0x62, 0x65, 0x72, 0x6f, 0x73,
22662306a36Sopenharmony_ci		      0x7b, 0x9b, 0x5b, 0x2b, 0x93, 0x13, 0x2b, 0x93,
22762306a36Sopenharmony_ci		      0x5c, 0x9b, 0xdc, 0xda, 0xd9, 0x5c, 0x98, 0x99,
22862306a36Sopenharmony_ci		      0xc4, 0xca, 0xe4, 0xde, 0xe6, 0xd6, 0xca, 0xe4
22962306a36Sopenharmony_ci);
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc3961_nfold_test_params[] = {
23262306a36Sopenharmony_ci	{
23362306a36Sopenharmony_ci		.desc			= "64-fold(\"012345\")",
23462306a36Sopenharmony_ci		.nfold			= 64,
23562306a36Sopenharmony_ci		.plaintext		= &nfold_test1_plaintext,
23662306a36Sopenharmony_ci		.expected_result	= &nfold_test1_expected_result,
23762306a36Sopenharmony_ci	},
23862306a36Sopenharmony_ci	{
23962306a36Sopenharmony_ci		.desc			= "56-fold(\"password\")",
24062306a36Sopenharmony_ci		.nfold			= 56,
24162306a36Sopenharmony_ci		.plaintext		= &nfold_test2_plaintext,
24262306a36Sopenharmony_ci		.expected_result	= &nfold_test2_expected_result,
24362306a36Sopenharmony_ci	},
24462306a36Sopenharmony_ci	{
24562306a36Sopenharmony_ci		.desc			= "64-fold(\"Rough Consensus, and Running Code\")",
24662306a36Sopenharmony_ci		.nfold			= 64,
24762306a36Sopenharmony_ci		.plaintext		= &nfold_test3_plaintext,
24862306a36Sopenharmony_ci		.expected_result	= &nfold_test3_expected_result,
24962306a36Sopenharmony_ci	},
25062306a36Sopenharmony_ci	{
25162306a36Sopenharmony_ci		.desc			= "168-fold(\"password\")",
25262306a36Sopenharmony_ci		.nfold			= 168,
25362306a36Sopenharmony_ci		.plaintext		= &nfold_test4_plaintext,
25462306a36Sopenharmony_ci		.expected_result	= &nfold_test4_expected_result,
25562306a36Sopenharmony_ci	},
25662306a36Sopenharmony_ci	{
25762306a36Sopenharmony_ci		.desc			= "192-fold(\"MASSACHVSETTS INSTITVTE OF TECHNOLOGY\")",
25862306a36Sopenharmony_ci		.nfold			= 192,
25962306a36Sopenharmony_ci		.plaintext		= &nfold_test5_plaintext,
26062306a36Sopenharmony_ci		.expected_result	= &nfold_test5_expected_result,
26162306a36Sopenharmony_ci	},
26262306a36Sopenharmony_ci	{
26362306a36Sopenharmony_ci		.desc			= "168-fold(\"Q\")",
26462306a36Sopenharmony_ci		.nfold			= 168,
26562306a36Sopenharmony_ci		.plaintext		= &nfold_test6_plaintext,
26662306a36Sopenharmony_ci		.expected_result	= &nfold_test6_expected_result,
26762306a36Sopenharmony_ci	},
26862306a36Sopenharmony_ci	{
26962306a36Sopenharmony_ci		.desc			= "168-fold(\"ba\")",
27062306a36Sopenharmony_ci		.nfold			= 168,
27162306a36Sopenharmony_ci		.plaintext		= &nfold_test7_plaintext,
27262306a36Sopenharmony_ci		.expected_result	= &nfold_test7_expected_result,
27362306a36Sopenharmony_ci	},
27462306a36Sopenharmony_ci	{
27562306a36Sopenharmony_ci		.desc			= "64-fold(\"kerberos\")",
27662306a36Sopenharmony_ci		.nfold			= 64,
27762306a36Sopenharmony_ci		.plaintext		= &nfold_test_kerberos,
27862306a36Sopenharmony_ci		.expected_result	= &nfold_test8_expected_result,
27962306a36Sopenharmony_ci	},
28062306a36Sopenharmony_ci	{
28162306a36Sopenharmony_ci		.desc			= "128-fold(\"kerberos\")",
28262306a36Sopenharmony_ci		.nfold			= 128,
28362306a36Sopenharmony_ci		.plaintext		= &nfold_test_kerberos,
28462306a36Sopenharmony_ci		.expected_result	= &nfold_test9_expected_result,
28562306a36Sopenharmony_ci	},
28662306a36Sopenharmony_ci	{
28762306a36Sopenharmony_ci		.desc			= "168-fold(\"kerberos\")",
28862306a36Sopenharmony_ci		.nfold			= 168,
28962306a36Sopenharmony_ci		.plaintext		= &nfold_test_kerberos,
29062306a36Sopenharmony_ci		.expected_result	= &nfold_test10_expected_result,
29162306a36Sopenharmony_ci	},
29262306a36Sopenharmony_ci	{
29362306a36Sopenharmony_ci		.desc			= "256-fold(\"kerberos\")",
29462306a36Sopenharmony_ci		.nfold			= 256,
29562306a36Sopenharmony_ci		.plaintext		= &nfold_test_kerberos,
29662306a36Sopenharmony_ci		.expected_result	= &nfold_test11_expected_result,
29762306a36Sopenharmony_ci	},
29862306a36Sopenharmony_ci};
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_ci/* Creates the function rfc3961_nfold_gen_params */
30162306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc3961_nfold, rfc3961_nfold_test_params, gss_krb5_get_desc);
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_cistatic void rfc3961_nfold_case(struct kunit *test)
30462306a36Sopenharmony_ci{
30562306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
30662306a36Sopenharmony_ci	u8 *result;
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci	/* Arrange */
30962306a36Sopenharmony_ci	result = kunit_kzalloc(test, 4096, GFP_KERNEL);
31062306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, result);
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	/* Act */
31362306a36Sopenharmony_ci	krb5_nfold(param->plaintext->len * 8, param->plaintext->data,
31462306a36Sopenharmony_ci		   param->expected_result->len * 8, result);
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci	/* Assert */
31762306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
31862306a36Sopenharmony_ci			    memcmp(param->expected_result->data,
31962306a36Sopenharmony_ci				   result, param->expected_result->len), 0,
32062306a36Sopenharmony_ci			    "result mismatch");
32162306a36Sopenharmony_ci}
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_cistatic struct kunit_case rfc3961_test_cases[] = {
32462306a36Sopenharmony_ci	{
32562306a36Sopenharmony_ci		.name			= "RFC 3961 n-fold",
32662306a36Sopenharmony_ci		.run_case		= rfc3961_nfold_case,
32762306a36Sopenharmony_ci		.generate_params	= rfc3961_nfold_gen_params,
32862306a36Sopenharmony_ci	},
32962306a36Sopenharmony_ci	{}
33062306a36Sopenharmony_ci};
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_cistatic struct kunit_suite rfc3961_suite = {
33362306a36Sopenharmony_ci	.name			= "RFC 3961 tests",
33462306a36Sopenharmony_ci	.test_cases		= rfc3961_test_cases,
33562306a36Sopenharmony_ci};
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci/*
33862306a36Sopenharmony_ci * From RFC 3962 Appendix B:   Sample Test Vectors
33962306a36Sopenharmony_ci *
34062306a36Sopenharmony_ci * Some test vectors for CBC with ciphertext stealing, using an
34162306a36Sopenharmony_ci * initial vector of all-zero.
34262306a36Sopenharmony_ci *
34362306a36Sopenharmony_ci * This test material is copyright (C) The Internet Society (2005).
34462306a36Sopenharmony_ci */
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_encryption_key,
34762306a36Sopenharmony_ci		      0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
34862306a36Sopenharmony_ci		      0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
34962306a36Sopenharmony_ci);
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test1_plaintext,
35262306a36Sopenharmony_ci		      0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
35362306a36Sopenharmony_ci		      0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
35462306a36Sopenharmony_ci		      0x20
35562306a36Sopenharmony_ci);
35662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test1_expected_result,
35762306a36Sopenharmony_ci		      0xc6, 0x35, 0x35, 0x68, 0xf2, 0xbf, 0x8c, 0xb4,
35862306a36Sopenharmony_ci		      0xd8, 0xa5, 0x80, 0x36, 0x2d, 0xa7, 0xff, 0x7f,
35962306a36Sopenharmony_ci		      0x97
36062306a36Sopenharmony_ci);
36162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test1_next_iv,
36262306a36Sopenharmony_ci		      0xc6, 0x35, 0x35, 0x68, 0xf2, 0xbf, 0x8c, 0xb4,
36362306a36Sopenharmony_ci		      0xd8, 0xa5, 0x80, 0x36, 0x2d, 0xa7, 0xff, 0x7f
36462306a36Sopenharmony_ci);
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test2_plaintext,
36762306a36Sopenharmony_ci		      0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
36862306a36Sopenharmony_ci		      0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
36962306a36Sopenharmony_ci		      0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
37062306a36Sopenharmony_ci		      0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20
37162306a36Sopenharmony_ci);
37262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test2_expected_result,
37362306a36Sopenharmony_ci		      0xfc, 0x00, 0x78, 0x3e, 0x0e, 0xfd, 0xb2, 0xc1,
37462306a36Sopenharmony_ci		      0xd4, 0x45, 0xd4, 0xc8, 0xef, 0xf7, 0xed, 0x22,
37562306a36Sopenharmony_ci		      0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
37662306a36Sopenharmony_ci		      0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5
37762306a36Sopenharmony_ci);
37862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test2_next_iv,
37962306a36Sopenharmony_ci		      0xfc, 0x00, 0x78, 0x3e, 0x0e, 0xfd, 0xb2, 0xc1,
38062306a36Sopenharmony_ci		      0xd4, 0x45, 0xd4, 0xc8, 0xef, 0xf7, 0xed, 0x22
38162306a36Sopenharmony_ci);
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test3_plaintext,
38462306a36Sopenharmony_ci		      0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
38562306a36Sopenharmony_ci		      0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
38662306a36Sopenharmony_ci		      0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
38762306a36Sopenharmony_ci		      0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43
38862306a36Sopenharmony_ci);
38962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test3_expected_result,
39062306a36Sopenharmony_ci		      0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
39162306a36Sopenharmony_ci		      0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8,
39262306a36Sopenharmony_ci		      0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
39362306a36Sopenharmony_ci		      0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84
39462306a36Sopenharmony_ci);
39562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test3_next_iv,
39662306a36Sopenharmony_ci		      0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
39762306a36Sopenharmony_ci		      0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8
39862306a36Sopenharmony_ci);
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test4_plaintext,
40162306a36Sopenharmony_ci		      0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
40262306a36Sopenharmony_ci		      0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
40362306a36Sopenharmony_ci		      0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
40462306a36Sopenharmony_ci		      0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43,
40562306a36Sopenharmony_ci		      0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x2c, 0x20,
40662306a36Sopenharmony_ci		      0x70, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x2c
40762306a36Sopenharmony_ci);
40862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test4_expected_result,
40962306a36Sopenharmony_ci		      0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
41062306a36Sopenharmony_ci		      0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84,
41162306a36Sopenharmony_ci		      0xb3, 0xff, 0xfd, 0x94, 0x0c, 0x16, 0xa1, 0x8c,
41262306a36Sopenharmony_ci		      0x1b, 0x55, 0x49, 0xd2, 0xf8, 0x38, 0x02, 0x9e,
41362306a36Sopenharmony_ci		      0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
41462306a36Sopenharmony_ci		      0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5
41562306a36Sopenharmony_ci);
41662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test4_next_iv,
41762306a36Sopenharmony_ci		      0xb3, 0xff, 0xfd, 0x94, 0x0c, 0x16, 0xa1, 0x8c,
41862306a36Sopenharmony_ci		      0x1b, 0x55, 0x49, 0xd2, 0xf8, 0x38, 0x02, 0x9e
41962306a36Sopenharmony_ci);
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test5_plaintext,
42262306a36Sopenharmony_ci		      0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
42362306a36Sopenharmony_ci		      0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
42462306a36Sopenharmony_ci		      0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
42562306a36Sopenharmony_ci		      0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43,
42662306a36Sopenharmony_ci		      0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x2c, 0x20,
42762306a36Sopenharmony_ci		      0x70, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x2c, 0x20
42862306a36Sopenharmony_ci);
42962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test5_expected_result,
43062306a36Sopenharmony_ci		      0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
43162306a36Sopenharmony_ci		      0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84,
43262306a36Sopenharmony_ci		      0x9d, 0xad, 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
43362306a36Sopenharmony_ci		      0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8,
43462306a36Sopenharmony_ci		      0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
43562306a36Sopenharmony_ci		      0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8
43662306a36Sopenharmony_ci);
43762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test5_next_iv,
43862306a36Sopenharmony_ci		      0x9d, 0xad, 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
43962306a36Sopenharmony_ci		      0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8
44062306a36Sopenharmony_ci);
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test6_plaintext,
44362306a36Sopenharmony_ci		      0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
44462306a36Sopenharmony_ci		      0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
44562306a36Sopenharmony_ci		      0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
44662306a36Sopenharmony_ci		      0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43,
44762306a36Sopenharmony_ci		      0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x2c, 0x20,
44862306a36Sopenharmony_ci		      0x70, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x2c, 0x20,
44962306a36Sopenharmony_ci		      0x61, 0x6e, 0x64, 0x20, 0x77, 0x6f, 0x6e, 0x74,
45062306a36Sopenharmony_ci		      0x6f, 0x6e, 0x20, 0x73, 0x6f, 0x75, 0x70, 0x2e
45162306a36Sopenharmony_ci);
45262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test6_expected_result,
45362306a36Sopenharmony_ci		      0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
45462306a36Sopenharmony_ci		      0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84,
45562306a36Sopenharmony_ci		      0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
45662306a36Sopenharmony_ci		      0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8,
45762306a36Sopenharmony_ci		      0x48, 0x07, 0xef, 0xe8, 0x36, 0xee, 0x89, 0xa5,
45862306a36Sopenharmony_ci		      0x26, 0x73, 0x0d, 0xbc, 0x2f, 0x7b, 0xc8, 0x40,
45962306a36Sopenharmony_ci		      0x9d, 0xad, 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
46062306a36Sopenharmony_ci		      0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8
46162306a36Sopenharmony_ci);
46262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test6_next_iv,
46362306a36Sopenharmony_ci		      0x48, 0x07, 0xef, 0xe8, 0x36, 0xee, 0x89, 0xa5,
46462306a36Sopenharmony_ci		      0x26, 0x73, 0x0d, 0xbc, 0x2f, 0x7b, 0xc8, 0x40
46562306a36Sopenharmony_ci);
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc3962_encrypt_test_params[] = {
46862306a36Sopenharmony_ci	{
46962306a36Sopenharmony_ci		.desc			= "Encrypt with aes128-cts-hmac-sha1-96 case 1",
47062306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
47162306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
47262306a36Sopenharmony_ci		.plaintext		= &rfc3962_enc_test1_plaintext,
47362306a36Sopenharmony_ci		.expected_result	= &rfc3962_enc_test1_expected_result,
47462306a36Sopenharmony_ci		.next_iv		= &rfc3962_enc_test1_next_iv,
47562306a36Sopenharmony_ci	},
47662306a36Sopenharmony_ci	{
47762306a36Sopenharmony_ci		.desc			= "Encrypt with aes128-cts-hmac-sha1-96 case 2",
47862306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
47962306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
48062306a36Sopenharmony_ci		.plaintext		= &rfc3962_enc_test2_plaintext,
48162306a36Sopenharmony_ci		.expected_result	= &rfc3962_enc_test2_expected_result,
48262306a36Sopenharmony_ci		.next_iv		= &rfc3962_enc_test2_next_iv,
48362306a36Sopenharmony_ci	},
48462306a36Sopenharmony_ci	{
48562306a36Sopenharmony_ci		.desc			= "Encrypt with aes128-cts-hmac-sha1-96 case 3",
48662306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
48762306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
48862306a36Sopenharmony_ci		.plaintext		= &rfc3962_enc_test3_plaintext,
48962306a36Sopenharmony_ci		.expected_result	= &rfc3962_enc_test3_expected_result,
49062306a36Sopenharmony_ci		.next_iv		= &rfc3962_enc_test3_next_iv,
49162306a36Sopenharmony_ci	},
49262306a36Sopenharmony_ci	{
49362306a36Sopenharmony_ci		.desc			= "Encrypt with aes128-cts-hmac-sha1-96 case 4",
49462306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
49562306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
49662306a36Sopenharmony_ci		.plaintext		= &rfc3962_enc_test4_plaintext,
49762306a36Sopenharmony_ci		.expected_result	= &rfc3962_enc_test4_expected_result,
49862306a36Sopenharmony_ci		.next_iv		= &rfc3962_enc_test4_next_iv,
49962306a36Sopenharmony_ci	},
50062306a36Sopenharmony_ci	{
50162306a36Sopenharmony_ci		.desc			= "Encrypt with aes128-cts-hmac-sha1-96 case 5",
50262306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
50362306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
50462306a36Sopenharmony_ci		.plaintext		= &rfc3962_enc_test5_plaintext,
50562306a36Sopenharmony_ci		.expected_result	= &rfc3962_enc_test5_expected_result,
50662306a36Sopenharmony_ci		.next_iv		= &rfc3962_enc_test5_next_iv,
50762306a36Sopenharmony_ci	},
50862306a36Sopenharmony_ci	{
50962306a36Sopenharmony_ci		.desc			= "Encrypt with aes128-cts-hmac-sha1-96 case 6",
51062306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
51162306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
51262306a36Sopenharmony_ci		.plaintext		= &rfc3962_enc_test6_plaintext,
51362306a36Sopenharmony_ci		.expected_result	= &rfc3962_enc_test6_expected_result,
51462306a36Sopenharmony_ci		.next_iv		= &rfc3962_enc_test6_next_iv,
51562306a36Sopenharmony_ci	},
51662306a36Sopenharmony_ci};
51762306a36Sopenharmony_ci
51862306a36Sopenharmony_ci/* Creates the function rfc3962_encrypt_gen_params */
51962306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc3962_encrypt, rfc3962_encrypt_test_params,
52062306a36Sopenharmony_ci		  gss_krb5_get_desc);
52162306a36Sopenharmony_ci
52262306a36Sopenharmony_ci/*
52362306a36Sopenharmony_ci * This tests the implementation of the encryption part of the mechanism.
52462306a36Sopenharmony_ci * It does not apply a confounder or test the result of HMAC over the
52562306a36Sopenharmony_ci * plaintext.
52662306a36Sopenharmony_ci */
52762306a36Sopenharmony_cistatic void rfc3962_encrypt_case(struct kunit *test)
52862306a36Sopenharmony_ci{
52962306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
53062306a36Sopenharmony_ci	struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
53162306a36Sopenharmony_ci	const struct gss_krb5_enctype *gk5e;
53262306a36Sopenharmony_ci	struct xdr_buf buf;
53362306a36Sopenharmony_ci	void *iv, *text;
53462306a36Sopenharmony_ci	u32 err;
53562306a36Sopenharmony_ci
53662306a36Sopenharmony_ci	/* Arrange */
53762306a36Sopenharmony_ci	gk5e = gss_krb5_lookup_enctype(param->enctype);
53862306a36Sopenharmony_ci	if (!gk5e)
53962306a36Sopenharmony_ci		kunit_skip(test, "Encryption type is not available");
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci	cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0, 0);
54262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
54362306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cbc_tfm, param->Ke->data, param->Ke->len);
54462306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ci	cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0, 0);
54762306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
54862306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cts_tfm, param->Ke->data, param->Ke->len);
54962306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci	iv = kunit_kzalloc(test, crypto_sync_skcipher_ivsize(cts_tfm), GFP_KERNEL);
55262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, iv);
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci	text = kunit_kzalloc(test, param->plaintext->len, GFP_KERNEL);
55562306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci	memcpy(text, param->plaintext->data, param->plaintext->len);
55862306a36Sopenharmony_ci	memset(&buf, 0, sizeof(buf));
55962306a36Sopenharmony_ci	buf.head[0].iov_base = text;
56062306a36Sopenharmony_ci	buf.head[0].iov_len = param->plaintext->len;
56162306a36Sopenharmony_ci	buf.len = buf.head[0].iov_len;
56262306a36Sopenharmony_ci
56362306a36Sopenharmony_ci	/* Act */
56462306a36Sopenharmony_ci	err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0, &buf, NULL,
56562306a36Sopenharmony_ci				   iv, crypto_sync_skcipher_ivsize(cts_tfm));
56662306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci	/* Assert */
56962306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
57062306a36Sopenharmony_ci			    param->expected_result->len, buf.len,
57162306a36Sopenharmony_ci			    "ciphertext length mismatch");
57262306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
57362306a36Sopenharmony_ci			    memcmp(param->expected_result->data,
57462306a36Sopenharmony_ci				   text, param->expected_result->len), 0,
57562306a36Sopenharmony_ci			    "ciphertext mismatch");
57662306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
57762306a36Sopenharmony_ci			    memcmp(param->next_iv->data, iv,
57862306a36Sopenharmony_ci				   param->next_iv->len), 0,
57962306a36Sopenharmony_ci			    "IV mismatch");
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ci	crypto_free_sync_skcipher(cts_tfm);
58262306a36Sopenharmony_ci	crypto_free_sync_skcipher(cbc_tfm);
58362306a36Sopenharmony_ci}
58462306a36Sopenharmony_ci
58562306a36Sopenharmony_cistatic struct kunit_case rfc3962_test_cases[] = {
58662306a36Sopenharmony_ci	{
58762306a36Sopenharmony_ci		.name			= "RFC 3962 encryption",
58862306a36Sopenharmony_ci		.run_case		= rfc3962_encrypt_case,
58962306a36Sopenharmony_ci		.generate_params	= rfc3962_encrypt_gen_params,
59062306a36Sopenharmony_ci	},
59162306a36Sopenharmony_ci	{}
59262306a36Sopenharmony_ci};
59362306a36Sopenharmony_ci
59462306a36Sopenharmony_cistatic struct kunit_suite rfc3962_suite = {
59562306a36Sopenharmony_ci	.name			= "RFC 3962 suite",
59662306a36Sopenharmony_ci	.test_cases		= rfc3962_test_cases,
59762306a36Sopenharmony_ci};
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci/*
60062306a36Sopenharmony_ci * From RFC 6803 Section 10.  Test vectors
60162306a36Sopenharmony_ci *
60262306a36Sopenharmony_ci * Sample results for key derivation
60362306a36Sopenharmony_ci *
60462306a36Sopenharmony_ci * Copyright (c) 2012 IETF Trust and the persons identified as the
60562306a36Sopenharmony_ci * document authors.  All rights reserved.
60662306a36Sopenharmony_ci */
60762306a36Sopenharmony_ci
60862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_basekey,
60962306a36Sopenharmony_ci		      0x57, 0xd0, 0x29, 0x72, 0x98, 0xff, 0xd9, 0xd3,
61062306a36Sopenharmony_ci		      0x5d, 0xe5, 0xa4, 0x7f, 0xb4, 0xbd, 0xe2, 0x4b
61162306a36Sopenharmony_ci);
61262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_Kc,
61362306a36Sopenharmony_ci		      0xd1, 0x55, 0x77, 0x5a, 0x20, 0x9d, 0x05, 0xf0,
61462306a36Sopenharmony_ci		      0x2b, 0x38, 0xd4, 0x2a, 0x38, 0x9e, 0x5a, 0x56
61562306a36Sopenharmony_ci);
61662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_Ke,
61762306a36Sopenharmony_ci		      0x64, 0xdf, 0x83, 0xf8, 0x5a, 0x53, 0x2f, 0x17,
61862306a36Sopenharmony_ci		      0x57, 0x7d, 0x8c, 0x37, 0x03, 0x57, 0x96, 0xab
61962306a36Sopenharmony_ci);
62062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_Ki,
62162306a36Sopenharmony_ci		      0x3e, 0x4f, 0xbd, 0xf3, 0x0f, 0xb8, 0x25, 0x9c,
62262306a36Sopenharmony_ci		      0x42, 0x5c, 0xb6, 0xc9, 0x6f, 0x1f, 0x46, 0x35
62362306a36Sopenharmony_ci);
62462306a36Sopenharmony_ci
62562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_basekey,
62662306a36Sopenharmony_ci		      0xb9, 0xd6, 0x82, 0x8b, 0x20, 0x56, 0xb7, 0xbe,
62762306a36Sopenharmony_ci		      0x65, 0x6d, 0x88, 0xa1, 0x23, 0xb1, 0xfa, 0xc6,
62862306a36Sopenharmony_ci		      0x82, 0x14, 0xac, 0x2b, 0x72, 0x7e, 0xcf, 0x5f,
62962306a36Sopenharmony_ci		      0x69, 0xaf, 0xe0, 0xc4, 0xdf, 0x2a, 0x6d, 0x2c
63062306a36Sopenharmony_ci);
63162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_Kc,
63262306a36Sopenharmony_ci		      0xe4, 0x67, 0xf9, 0xa9, 0x55, 0x2b, 0xc7, 0xd3,
63362306a36Sopenharmony_ci		      0x15, 0x5a, 0x62, 0x20, 0xaf, 0x9c, 0x19, 0x22,
63462306a36Sopenharmony_ci		      0x0e, 0xee, 0xd4, 0xff, 0x78, 0xb0, 0xd1, 0xe6,
63562306a36Sopenharmony_ci		      0xa1, 0x54, 0x49, 0x91, 0x46, 0x1a, 0x9e, 0x50
63662306a36Sopenharmony_ci);
63762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_Ke,
63862306a36Sopenharmony_ci		      0x41, 0x2a, 0xef, 0xc3, 0x62, 0xa7, 0x28, 0x5f,
63962306a36Sopenharmony_ci		      0xc3, 0x96, 0x6c, 0x6a, 0x51, 0x81, 0xe7, 0x60,
64062306a36Sopenharmony_ci		      0x5a, 0xe6, 0x75, 0x23, 0x5b, 0x6d, 0x54, 0x9f,
64162306a36Sopenharmony_ci		      0xbf, 0xc9, 0xab, 0x66, 0x30, 0xa4, 0xc6, 0x04
64262306a36Sopenharmony_ci);
64362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_Ki,
64462306a36Sopenharmony_ci		      0xfa, 0x62, 0x4f, 0xa0, 0xe5, 0x23, 0x99, 0x3f,
64562306a36Sopenharmony_ci		      0xa3, 0x88, 0xae, 0xfd, 0xc6, 0x7e, 0x67, 0xeb,
64662306a36Sopenharmony_ci		      0xcd, 0x8c, 0x08, 0xe8, 0xa0, 0x24, 0x6b, 0x1d,
64762306a36Sopenharmony_ci		      0x73, 0xb0, 0xd1, 0xdd, 0x9f, 0xc5, 0x82, 0xb0
64862306a36Sopenharmony_ci);
64962306a36Sopenharmony_ci
65062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(usage_checksum,
65162306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x02, KEY_USAGE_SEED_CHECKSUM
65262306a36Sopenharmony_ci);
65362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(usage_encryption,
65462306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x02, KEY_USAGE_SEED_ENCRYPTION
65562306a36Sopenharmony_ci);
65662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(usage_integrity,
65762306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x02, KEY_USAGE_SEED_INTEGRITY
65862306a36Sopenharmony_ci);
65962306a36Sopenharmony_ci
66062306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc6803_kdf_test_params[] = {
66162306a36Sopenharmony_ci	{
66262306a36Sopenharmony_ci		.desc			= "Derive Kc subkey for camellia128-cts-cmac",
66362306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
66462306a36Sopenharmony_ci		.base_key		= &camellia128_cts_cmac_basekey,
66562306a36Sopenharmony_ci		.usage			= &usage_checksum,
66662306a36Sopenharmony_ci		.expected_result	= &camellia128_cts_cmac_Kc,
66762306a36Sopenharmony_ci	},
66862306a36Sopenharmony_ci	{
66962306a36Sopenharmony_ci		.desc			= "Derive Ke subkey for camellia128-cts-cmac",
67062306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
67162306a36Sopenharmony_ci		.base_key		= &camellia128_cts_cmac_basekey,
67262306a36Sopenharmony_ci		.usage			= &usage_encryption,
67362306a36Sopenharmony_ci		.expected_result	= &camellia128_cts_cmac_Ke,
67462306a36Sopenharmony_ci	},
67562306a36Sopenharmony_ci	{
67662306a36Sopenharmony_ci		.desc			= "Derive Ki subkey for camellia128-cts-cmac",
67762306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
67862306a36Sopenharmony_ci		.base_key		= &camellia128_cts_cmac_basekey,
67962306a36Sopenharmony_ci		.usage			= &usage_integrity,
68062306a36Sopenharmony_ci		.expected_result	= &camellia128_cts_cmac_Ki,
68162306a36Sopenharmony_ci	},
68262306a36Sopenharmony_ci	{
68362306a36Sopenharmony_ci		.desc			= "Derive Kc subkey for camellia256-cts-cmac",
68462306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
68562306a36Sopenharmony_ci		.base_key		= &camellia256_cts_cmac_basekey,
68662306a36Sopenharmony_ci		.usage			= &usage_checksum,
68762306a36Sopenharmony_ci		.expected_result	= &camellia256_cts_cmac_Kc,
68862306a36Sopenharmony_ci	},
68962306a36Sopenharmony_ci	{
69062306a36Sopenharmony_ci		.desc			= "Derive Ke subkey for camellia256-cts-cmac",
69162306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
69262306a36Sopenharmony_ci		.base_key		= &camellia256_cts_cmac_basekey,
69362306a36Sopenharmony_ci		.usage			= &usage_encryption,
69462306a36Sopenharmony_ci		.expected_result	= &camellia256_cts_cmac_Ke,
69562306a36Sopenharmony_ci	},
69662306a36Sopenharmony_ci	{
69762306a36Sopenharmony_ci		.desc			= "Derive Ki subkey for camellia256-cts-cmac",
69862306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
69962306a36Sopenharmony_ci		.base_key		= &camellia256_cts_cmac_basekey,
70062306a36Sopenharmony_ci		.usage			= &usage_integrity,
70162306a36Sopenharmony_ci		.expected_result	= &camellia256_cts_cmac_Ki,
70262306a36Sopenharmony_ci	},
70362306a36Sopenharmony_ci};
70462306a36Sopenharmony_ci
70562306a36Sopenharmony_ci/* Creates the function rfc6803_kdf_gen_params */
70662306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc6803_kdf, rfc6803_kdf_test_params, gss_krb5_get_desc);
70762306a36Sopenharmony_ci
70862306a36Sopenharmony_ci/*
70962306a36Sopenharmony_ci * From RFC 6803 Section 10.  Test vectors
71062306a36Sopenharmony_ci *
71162306a36Sopenharmony_ci * Sample checksums.
71262306a36Sopenharmony_ci *
71362306a36Sopenharmony_ci * Copyright (c) 2012 IETF Trust and the persons identified as the
71462306a36Sopenharmony_ci * document authors.  All rights reserved.
71562306a36Sopenharmony_ci *
71662306a36Sopenharmony_ci * XXX: These tests are likely to fail on EBCDIC or Unicode platforms.
71762306a36Sopenharmony_ci */
71862306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test1_plaintext,
71962306a36Sopenharmony_ci		      "abcdefghijk");
72062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test1_basekey,
72162306a36Sopenharmony_ci		      0x1d, 0xc4, 0x6a, 0x8d, 0x76, 0x3f, 0x4f, 0x93,
72262306a36Sopenharmony_ci		      0x74, 0x2b, 0xcb, 0xa3, 0x38, 0x75, 0x76, 0xc3
72362306a36Sopenharmony_ci);
72462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test1_usage,
72562306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x07, KEY_USAGE_SEED_CHECKSUM
72662306a36Sopenharmony_ci);
72762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test1_expected_result,
72862306a36Sopenharmony_ci		      0x11, 0x78, 0xe6, 0xc5, 0xc4, 0x7a, 0x8c, 0x1a,
72962306a36Sopenharmony_ci		      0xe0, 0xc4, 0xb9, 0xc7, 0xd4, 0xeb, 0x7b, 0x6b
73062306a36Sopenharmony_ci);
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test2_plaintext,
73362306a36Sopenharmony_ci		      "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
73462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test2_basekey,
73562306a36Sopenharmony_ci		      0x50, 0x27, 0xbc, 0x23, 0x1d, 0x0f, 0x3a, 0x9d,
73662306a36Sopenharmony_ci		      0x23, 0x33, 0x3f, 0x1c, 0xa6, 0xfd, 0xbe, 0x7c
73762306a36Sopenharmony_ci);
73862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test2_usage,
73962306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x08, KEY_USAGE_SEED_CHECKSUM
74062306a36Sopenharmony_ci);
74162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test2_expected_result,
74262306a36Sopenharmony_ci		      0xd1, 0xb3, 0x4f, 0x70, 0x04, 0xa7, 0x31, 0xf2,
74362306a36Sopenharmony_ci		      0x3a, 0x0c, 0x00, 0xbf, 0x6c, 0x3f, 0x75, 0x3a
74462306a36Sopenharmony_ci);
74562306a36Sopenharmony_ci
74662306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test3_plaintext,
74762306a36Sopenharmony_ci		      "123456789");
74862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test3_basekey,
74962306a36Sopenharmony_ci		      0xb6, 0x1c, 0x86, 0xcc, 0x4e, 0x5d, 0x27, 0x57,
75062306a36Sopenharmony_ci		      0x54, 0x5a, 0xd4, 0x23, 0x39, 0x9f, 0xb7, 0x03,
75162306a36Sopenharmony_ci		      0x1e, 0xca, 0xb9, 0x13, 0xcb, 0xb9, 0x00, 0xbd,
75262306a36Sopenharmony_ci		      0x7a, 0x3c, 0x6d, 0xd8, 0xbf, 0x92, 0x01, 0x5b
75362306a36Sopenharmony_ci);
75462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test3_usage,
75562306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x09, KEY_USAGE_SEED_CHECKSUM
75662306a36Sopenharmony_ci);
75762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test3_expected_result,
75862306a36Sopenharmony_ci		      0x87, 0xa1, 0x2c, 0xfd, 0x2b, 0x96, 0x21, 0x48,
75962306a36Sopenharmony_ci		      0x10, 0xf0, 0x1c, 0x82, 0x6e, 0x77, 0x44, 0xb1
76062306a36Sopenharmony_ci);
76162306a36Sopenharmony_ci
76262306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test4_plaintext,
76362306a36Sopenharmony_ci		      "!@#$%^&*()!@#$%^&*()!@#$%^&*()");
76462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test4_basekey,
76562306a36Sopenharmony_ci		      0x32, 0x16, 0x4c, 0x5b, 0x43, 0x4d, 0x1d, 0x15,
76662306a36Sopenharmony_ci		      0x38, 0xe4, 0xcf, 0xd9, 0xbe, 0x80, 0x40, 0xfe,
76762306a36Sopenharmony_ci		      0x8c, 0x4a, 0xc7, 0xac, 0xc4, 0xb9, 0x3d, 0x33,
76862306a36Sopenharmony_ci		      0x14, 0xd2, 0x13, 0x36, 0x68, 0x14, 0x7a, 0x05
76962306a36Sopenharmony_ci);
77062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test4_usage,
77162306a36Sopenharmony_ci		      0x00, 0x00, 0x00, 0x0a, KEY_USAGE_SEED_CHECKSUM
77262306a36Sopenharmony_ci);
77362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test4_expected_result,
77462306a36Sopenharmony_ci		      0x3f, 0xa0, 0xb4, 0x23, 0x55, 0xe5, 0x2b, 0x18,
77562306a36Sopenharmony_ci		      0x91, 0x87, 0x29, 0x4a, 0xa2, 0x52, 0xab, 0x64
77662306a36Sopenharmony_ci);
77762306a36Sopenharmony_ci
77862306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc6803_checksum_test_params[] = {
77962306a36Sopenharmony_ci	{
78062306a36Sopenharmony_ci		.desc			= "camellia128-cts-cmac checksum test 1",
78162306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
78262306a36Sopenharmony_ci		.base_key		= &rfc6803_checksum_test1_basekey,
78362306a36Sopenharmony_ci		.usage			= &rfc6803_checksum_test1_usage,
78462306a36Sopenharmony_ci		.plaintext		= &rfc6803_checksum_test1_plaintext,
78562306a36Sopenharmony_ci		.expected_result	= &rfc6803_checksum_test1_expected_result,
78662306a36Sopenharmony_ci	},
78762306a36Sopenharmony_ci	{
78862306a36Sopenharmony_ci		.desc			= "camellia128-cts-cmac checksum test 2",
78962306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
79062306a36Sopenharmony_ci		.base_key		= &rfc6803_checksum_test2_basekey,
79162306a36Sopenharmony_ci		.usage			= &rfc6803_checksum_test2_usage,
79262306a36Sopenharmony_ci		.plaintext		= &rfc6803_checksum_test2_plaintext,
79362306a36Sopenharmony_ci		.expected_result	= &rfc6803_checksum_test2_expected_result,
79462306a36Sopenharmony_ci	},
79562306a36Sopenharmony_ci	{
79662306a36Sopenharmony_ci		.desc			= "camellia256-cts-cmac checksum test 3",
79762306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
79862306a36Sopenharmony_ci		.base_key		= &rfc6803_checksum_test3_basekey,
79962306a36Sopenharmony_ci		.usage			= &rfc6803_checksum_test3_usage,
80062306a36Sopenharmony_ci		.plaintext		= &rfc6803_checksum_test3_plaintext,
80162306a36Sopenharmony_ci		.expected_result	= &rfc6803_checksum_test3_expected_result,
80262306a36Sopenharmony_ci	},
80362306a36Sopenharmony_ci	{
80462306a36Sopenharmony_ci		.desc			= "camellia256-cts-cmac checksum test 4",
80562306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
80662306a36Sopenharmony_ci		.base_key		= &rfc6803_checksum_test4_basekey,
80762306a36Sopenharmony_ci		.usage			= &rfc6803_checksum_test4_usage,
80862306a36Sopenharmony_ci		.plaintext		= &rfc6803_checksum_test4_plaintext,
80962306a36Sopenharmony_ci		.expected_result	= &rfc6803_checksum_test4_expected_result,
81062306a36Sopenharmony_ci	},
81162306a36Sopenharmony_ci};
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ci/* Creates the function rfc6803_checksum_gen_params */
81462306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc6803_checksum, rfc6803_checksum_test_params,
81562306a36Sopenharmony_ci		  gss_krb5_get_desc);
81662306a36Sopenharmony_ci
81762306a36Sopenharmony_ci/*
81862306a36Sopenharmony_ci * From RFC 6803 Section 10.  Test vectors
81962306a36Sopenharmony_ci *
82062306a36Sopenharmony_ci * Sample encryptions (all using the default cipher state)
82162306a36Sopenharmony_ci *
82262306a36Sopenharmony_ci * Copyright (c) 2012 IETF Trust and the persons identified as the
82362306a36Sopenharmony_ci * document authors.  All rights reserved.
82462306a36Sopenharmony_ci *
82562306a36Sopenharmony_ci * Key usage values are from errata 4326 against RFC 6803.
82662306a36Sopenharmony_ci */
82762306a36Sopenharmony_ci
82862306a36Sopenharmony_cistatic const struct xdr_netobj rfc6803_enc_empty_plaintext = {
82962306a36Sopenharmony_ci	.len	= 0,
83062306a36Sopenharmony_ci};
83162306a36Sopenharmony_ci
83262306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_enc_1byte_plaintext, "1");
83362306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_enc_9byte_plaintext, "9 bytesss");
83462306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_enc_13byte_plaintext, "13 bytes byte");
83562306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(rfc6803_enc_30byte_plaintext,
83662306a36Sopenharmony_ci		      "30 bytes bytes bytes bytes byt"
83762306a36Sopenharmony_ci);
83862306a36Sopenharmony_ci
83962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test1_confounder,
84062306a36Sopenharmony_ci		      0xb6, 0x98, 0x22, 0xa1, 0x9a, 0x6b, 0x09, 0xc0,
84162306a36Sopenharmony_ci		      0xeb, 0xc8, 0x55, 0x7d, 0x1f, 0x1b, 0x6c, 0x0a
84262306a36Sopenharmony_ci);
84362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test1_basekey,
84462306a36Sopenharmony_ci		      0x1d, 0xc4, 0x6a, 0x8d, 0x76, 0x3f, 0x4f, 0x93,
84562306a36Sopenharmony_ci		      0x74, 0x2b, 0xcb, 0xa3, 0x38, 0x75, 0x76, 0xc3
84662306a36Sopenharmony_ci);
84762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test1_expected_result,
84862306a36Sopenharmony_ci		      0xc4, 0x66, 0xf1, 0x87, 0x10, 0x69, 0x92, 0x1e,
84962306a36Sopenharmony_ci		      0xdb, 0x7c, 0x6f, 0xde, 0x24, 0x4a, 0x52, 0xdb,
85062306a36Sopenharmony_ci		      0x0b, 0xa1, 0x0e, 0xdc, 0x19, 0x7b, 0xdb, 0x80,
85162306a36Sopenharmony_ci		      0x06, 0x65, 0x8c, 0xa3, 0xcc, 0xce, 0x6e, 0xb8
85262306a36Sopenharmony_ci);
85362306a36Sopenharmony_ci
85462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test2_confounder,
85562306a36Sopenharmony_ci		      0x6f, 0x2f, 0xc3, 0xc2, 0xa1, 0x66, 0xfd, 0x88,
85662306a36Sopenharmony_ci		      0x98, 0x96, 0x7a, 0x83, 0xde, 0x95, 0x96, 0xd9
85762306a36Sopenharmony_ci);
85862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test2_basekey,
85962306a36Sopenharmony_ci		      0x50, 0x27, 0xbc, 0x23, 0x1d, 0x0f, 0x3a, 0x9d,
86062306a36Sopenharmony_ci		      0x23, 0x33, 0x3f, 0x1c, 0xa6, 0xfd, 0xbe, 0x7c
86162306a36Sopenharmony_ci);
86262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test2_expected_result,
86362306a36Sopenharmony_ci		      0x84, 0x2d, 0x21, 0xfd, 0x95, 0x03, 0x11, 0xc0,
86462306a36Sopenharmony_ci		      0xdd, 0x46, 0x4a, 0x3f, 0x4b, 0xe8, 0xd6, 0xda,
86562306a36Sopenharmony_ci		      0x88, 0xa5, 0x6d, 0x55, 0x9c, 0x9b, 0x47, 0xd3,
86662306a36Sopenharmony_ci		      0xf9, 0xa8, 0x50, 0x67, 0xaf, 0x66, 0x15, 0x59,
86762306a36Sopenharmony_ci		      0xb8
86862306a36Sopenharmony_ci);
86962306a36Sopenharmony_ci
87062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test3_confounder,
87162306a36Sopenharmony_ci		      0xa5, 0xb4, 0xa7, 0x1e, 0x07, 0x7a, 0xee, 0xf9,
87262306a36Sopenharmony_ci		      0x3c, 0x87, 0x63, 0xc1, 0x8f, 0xdb, 0x1f, 0x10
87362306a36Sopenharmony_ci);
87462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test3_basekey,
87562306a36Sopenharmony_ci		      0xa1, 0xbb, 0x61, 0xe8, 0x05, 0xf9, 0xba, 0x6d,
87662306a36Sopenharmony_ci		      0xde, 0x8f, 0xdb, 0xdd, 0xc0, 0x5c, 0xde, 0xa0
87762306a36Sopenharmony_ci);
87862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test3_expected_result,
87962306a36Sopenharmony_ci		      0x61, 0x9f, 0xf0, 0x72, 0xe3, 0x62, 0x86, 0xff,
88062306a36Sopenharmony_ci		      0x0a, 0x28, 0xde, 0xb3, 0xa3, 0x52, 0xec, 0x0d,
88162306a36Sopenharmony_ci		      0x0e, 0xdf, 0x5c, 0x51, 0x60, 0xd6, 0x63, 0xc9,
88262306a36Sopenharmony_ci		      0x01, 0x75, 0x8c, 0xcf, 0x9d, 0x1e, 0xd3, 0x3d,
88362306a36Sopenharmony_ci		      0x71, 0xdb, 0x8f, 0x23, 0xaa, 0xbf, 0x83, 0x48,
88462306a36Sopenharmony_ci		      0xa0
88562306a36Sopenharmony_ci);
88662306a36Sopenharmony_ci
88762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test4_confounder,
88862306a36Sopenharmony_ci		      0x19, 0xfe, 0xe4, 0x0d, 0x81, 0x0c, 0x52, 0x4b,
88962306a36Sopenharmony_ci		      0x5b, 0x22, 0xf0, 0x18, 0x74, 0xc6, 0x93, 0xda
89062306a36Sopenharmony_ci);
89162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test4_basekey,
89262306a36Sopenharmony_ci		      0x2c, 0xa2, 0x7a, 0x5f, 0xaf, 0x55, 0x32, 0x24,
89362306a36Sopenharmony_ci		      0x45, 0x06, 0x43, 0x4e, 0x1c, 0xef, 0x66, 0x76
89462306a36Sopenharmony_ci);
89562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test4_expected_result,
89662306a36Sopenharmony_ci		      0xb8, 0xec, 0xa3, 0x16, 0x7a, 0xe6, 0x31, 0x55,
89762306a36Sopenharmony_ci		      0x12, 0xe5, 0x9f, 0x98, 0xa7, 0xc5, 0x00, 0x20,
89862306a36Sopenharmony_ci		      0x5e, 0x5f, 0x63, 0xff, 0x3b, 0xb3, 0x89, 0xaf,
89962306a36Sopenharmony_ci		      0x1c, 0x41, 0xa2, 0x1d, 0x64, 0x0d, 0x86, 0x15,
90062306a36Sopenharmony_ci		      0xc9, 0xed, 0x3f, 0xbe, 0xb0, 0x5a, 0xb6, 0xac,
90162306a36Sopenharmony_ci		      0xb6, 0x76, 0x89, 0xb5, 0xea
90262306a36Sopenharmony_ci);
90362306a36Sopenharmony_ci
90462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test5_confounder,
90562306a36Sopenharmony_ci		      0xca, 0x7a, 0x7a, 0xb4, 0xbe, 0x19, 0x2d, 0xab,
90662306a36Sopenharmony_ci		      0xd6, 0x03, 0x50, 0x6d, 0xb1, 0x9c, 0x39, 0xe2
90762306a36Sopenharmony_ci);
90862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test5_basekey,
90962306a36Sopenharmony_ci		      0x78, 0x24, 0xf8, 0xc1, 0x6f, 0x83, 0xff, 0x35,
91062306a36Sopenharmony_ci		      0x4c, 0x6b, 0xf7, 0x51, 0x5b, 0x97, 0x3f, 0x43
91162306a36Sopenharmony_ci);
91262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test5_expected_result,
91362306a36Sopenharmony_ci		      0xa2, 0x6a, 0x39, 0x05, 0xa4, 0xff, 0xd5, 0x81,
91462306a36Sopenharmony_ci		      0x6b, 0x7b, 0x1e, 0x27, 0x38, 0x0d, 0x08, 0x09,
91562306a36Sopenharmony_ci		      0x0c, 0x8e, 0xc1, 0xf3, 0x04, 0x49, 0x6e, 0x1a,
91662306a36Sopenharmony_ci		      0xbd, 0xcd, 0x2b, 0xdc, 0xd1, 0xdf, 0xfc, 0x66,
91762306a36Sopenharmony_ci		      0x09, 0x89, 0xe1, 0x17, 0xa7, 0x13, 0xdd, 0xbb,
91862306a36Sopenharmony_ci		      0x57, 0xa4, 0x14, 0x6c, 0x15, 0x87, 0xcb, 0xa4,
91962306a36Sopenharmony_ci		      0x35, 0x66, 0x65, 0x59, 0x1d, 0x22, 0x40, 0x28,
92062306a36Sopenharmony_ci		      0x2f, 0x58, 0x42, 0xb1, 0x05, 0xa5
92162306a36Sopenharmony_ci);
92262306a36Sopenharmony_ci
92362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test6_confounder,
92462306a36Sopenharmony_ci		      0x3c, 0xbb, 0xd2, 0xb4, 0x59, 0x17, 0x94, 0x10,
92562306a36Sopenharmony_ci		      0x67, 0xf9, 0x65, 0x99, 0xbb, 0x98, 0x92, 0x6c
92662306a36Sopenharmony_ci);
92762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test6_basekey,
92862306a36Sopenharmony_ci		      0xb6, 0x1c, 0x86, 0xcc, 0x4e, 0x5d, 0x27, 0x57,
92962306a36Sopenharmony_ci		      0x54, 0x5a, 0xd4, 0x23, 0x39, 0x9f, 0xb7, 0x03,
93062306a36Sopenharmony_ci		      0x1e, 0xca, 0xb9, 0x13, 0xcb, 0xb9, 0x00, 0xbd,
93162306a36Sopenharmony_ci		      0x7a, 0x3c, 0x6d, 0xd8, 0xbf, 0x92, 0x01, 0x5b
93262306a36Sopenharmony_ci);
93362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test6_expected_result,
93462306a36Sopenharmony_ci		      0x03, 0x88, 0x6d, 0x03, 0x31, 0x0b, 0x47, 0xa6,
93562306a36Sopenharmony_ci		      0xd8, 0xf0, 0x6d, 0x7b, 0x94, 0xd1, 0xdd, 0x83,
93662306a36Sopenharmony_ci		      0x7e, 0xcc, 0xe3, 0x15, 0xef, 0x65, 0x2a, 0xff,
93762306a36Sopenharmony_ci		      0x62, 0x08, 0x59, 0xd9, 0x4a, 0x25, 0x92, 0x66
93862306a36Sopenharmony_ci);
93962306a36Sopenharmony_ci
94062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test7_confounder,
94162306a36Sopenharmony_ci		      0xde, 0xf4, 0x87, 0xfc, 0xeb, 0xe6, 0xde, 0x63,
94262306a36Sopenharmony_ci		      0x46, 0xd4, 0xda, 0x45, 0x21, 0xbb, 0xa2, 0xd2
94362306a36Sopenharmony_ci);
94462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test7_basekey,
94562306a36Sopenharmony_ci		      0x1b, 0x97, 0xfe, 0x0a, 0x19, 0x0e, 0x20, 0x21,
94662306a36Sopenharmony_ci		      0xeb, 0x30, 0x75, 0x3e, 0x1b, 0x6e, 0x1e, 0x77,
94762306a36Sopenharmony_ci		      0xb0, 0x75, 0x4b, 0x1d, 0x68, 0x46, 0x10, 0x35,
94862306a36Sopenharmony_ci		      0x58, 0x64, 0x10, 0x49, 0x63, 0x46, 0x38, 0x33
94962306a36Sopenharmony_ci);
95062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test7_expected_result,
95162306a36Sopenharmony_ci		      0x2c, 0x9c, 0x15, 0x70, 0x13, 0x3c, 0x99, 0xbf,
95262306a36Sopenharmony_ci		      0x6a, 0x34, 0xbc, 0x1b, 0x02, 0x12, 0x00, 0x2f,
95362306a36Sopenharmony_ci		      0xd1, 0x94, 0x33, 0x87, 0x49, 0xdb, 0x41, 0x35,
95462306a36Sopenharmony_ci		      0x49, 0x7a, 0x34, 0x7c, 0xfc, 0xd9, 0xd1, 0x8a,
95562306a36Sopenharmony_ci		      0x12
95662306a36Sopenharmony_ci);
95762306a36Sopenharmony_ci
95862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test8_confounder,
95962306a36Sopenharmony_ci		      0xad, 0x4f, 0xf9, 0x04, 0xd3, 0x4e, 0x55, 0x53,
96062306a36Sopenharmony_ci		      0x84, 0xb1, 0x41, 0x00, 0xfc, 0x46, 0x5f, 0x88
96162306a36Sopenharmony_ci);
96262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test8_basekey,
96362306a36Sopenharmony_ci		      0x32, 0x16, 0x4c, 0x5b, 0x43, 0x4d, 0x1d, 0x15,
96462306a36Sopenharmony_ci		      0x38, 0xe4, 0xcf, 0xd9, 0xbe, 0x80, 0x40, 0xfe,
96562306a36Sopenharmony_ci		      0x8c, 0x4a, 0xc7, 0xac, 0xc4, 0xb9, 0x3d, 0x33,
96662306a36Sopenharmony_ci		      0x14, 0xd2, 0x13, 0x36, 0x68, 0x14, 0x7a, 0x05
96762306a36Sopenharmony_ci);
96862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test8_expected_result,
96962306a36Sopenharmony_ci		      0x9c, 0x6d, 0xe7, 0x5f, 0x81, 0x2d, 0xe7, 0xed,
97062306a36Sopenharmony_ci		      0x0d, 0x28, 0xb2, 0x96, 0x35, 0x57, 0xa1, 0x15,
97162306a36Sopenharmony_ci		      0x64, 0x09, 0x98, 0x27, 0x5b, 0x0a, 0xf5, 0x15,
97262306a36Sopenharmony_ci		      0x27, 0x09, 0x91, 0x3f, 0xf5, 0x2a, 0x2a, 0x9c,
97362306a36Sopenharmony_ci		      0x8e, 0x63, 0xb8, 0x72, 0xf9, 0x2e, 0x64, 0xc8,
97462306a36Sopenharmony_ci		      0x39
97562306a36Sopenharmony_ci);
97662306a36Sopenharmony_ci
97762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test9_confounder,
97862306a36Sopenharmony_ci		      0xcf, 0x9b, 0xca, 0x6d, 0xf1, 0x14, 0x4e, 0x0c,
97962306a36Sopenharmony_ci		      0x0a, 0xf9, 0xb8, 0xf3, 0x4c, 0x90, 0xd5, 0x14
98062306a36Sopenharmony_ci);
98162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test9_basekey,
98262306a36Sopenharmony_ci		      0xb0, 0x38, 0xb1, 0x32, 0xcd, 0x8e, 0x06, 0x61,
98362306a36Sopenharmony_ci		      0x22, 0x67, 0xfa, 0xb7, 0x17, 0x00, 0x66, 0xd8,
98462306a36Sopenharmony_ci		      0x8a, 0xec, 0xcb, 0xa0, 0xb7, 0x44, 0xbf, 0xc6,
98562306a36Sopenharmony_ci		      0x0d, 0xc8, 0x9b, 0xca, 0x18, 0x2d, 0x07, 0x15
98662306a36Sopenharmony_ci);
98762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test9_expected_result,
98862306a36Sopenharmony_ci		      0xee, 0xec, 0x85, 0xa9, 0x81, 0x3c, 0xdc, 0x53,
98962306a36Sopenharmony_ci		      0x67, 0x72, 0xab, 0x9b, 0x42, 0xde, 0xfc, 0x57,
99062306a36Sopenharmony_ci		      0x06, 0xf7, 0x26, 0xe9, 0x75, 0xdd, 0xe0, 0x5a,
99162306a36Sopenharmony_ci		      0x87, 0xeb, 0x54, 0x06, 0xea, 0x32, 0x4c, 0xa1,
99262306a36Sopenharmony_ci		      0x85, 0xc9, 0x98, 0x6b, 0x42, 0xaa, 0xbe, 0x79,
99362306a36Sopenharmony_ci		      0x4b, 0x84, 0x82, 0x1b, 0xee
99462306a36Sopenharmony_ci);
99562306a36Sopenharmony_ci
99662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test10_confounder,
99762306a36Sopenharmony_ci		      0x64, 0x4d, 0xef, 0x38, 0xda, 0x35, 0x00, 0x72,
99862306a36Sopenharmony_ci		      0x75, 0x87, 0x8d, 0x21, 0x68, 0x55, 0xe2, 0x28
99962306a36Sopenharmony_ci);
100062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test10_basekey,
100162306a36Sopenharmony_ci		      0xcc, 0xfc, 0xd3, 0x49, 0xbf, 0x4c, 0x66, 0x77,
100262306a36Sopenharmony_ci		      0xe8, 0x6e, 0x4b, 0x02, 0xb8, 0xea, 0xb9, 0x24,
100362306a36Sopenharmony_ci		      0xa5, 0x46, 0xac, 0x73, 0x1c, 0xf9, 0xbf, 0x69,
100462306a36Sopenharmony_ci		      0x89, 0xb9, 0x96, 0xe7, 0xd6, 0xbf, 0xbb, 0xa7
100562306a36Sopenharmony_ci);
100662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test10_expected_result,
100762306a36Sopenharmony_ci		      0x0e, 0x44, 0x68, 0x09, 0x85, 0x85, 0x5f, 0x2d,
100862306a36Sopenharmony_ci		      0x1f, 0x18, 0x12, 0x52, 0x9c, 0xa8, 0x3b, 0xfd,
100962306a36Sopenharmony_ci		      0x8e, 0x34, 0x9d, 0xe6, 0xfd, 0x9a, 0xda, 0x0b,
101062306a36Sopenharmony_ci		      0xaa, 0xa0, 0x48, 0xd6, 0x8e, 0x26, 0x5f, 0xeb,
101162306a36Sopenharmony_ci		      0xf3, 0x4a, 0xd1, 0x25, 0x5a, 0x34, 0x49, 0x99,
101262306a36Sopenharmony_ci		      0xad, 0x37, 0x14, 0x68, 0x87, 0xa6, 0xc6, 0x84,
101362306a36Sopenharmony_ci		      0x57, 0x31, 0xac, 0x7f, 0x46, 0x37, 0x6a, 0x05,
101462306a36Sopenharmony_ci		      0x04, 0xcd, 0x06, 0x57, 0x14, 0x74
101562306a36Sopenharmony_ci);
101662306a36Sopenharmony_ci
101762306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc6803_encrypt_test_params[] = {
101862306a36Sopenharmony_ci	{
101962306a36Sopenharmony_ci		.desc			= "Encrypt empty plaintext with camellia128-cts-cmac",
102062306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
102162306a36Sopenharmony_ci		.constant		= 0,
102262306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test1_basekey,
102362306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_empty_plaintext,
102462306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test1_confounder,
102562306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test1_expected_result,
102662306a36Sopenharmony_ci	},
102762306a36Sopenharmony_ci	{
102862306a36Sopenharmony_ci		.desc			= "Encrypt 1 byte with camellia128-cts-cmac",
102962306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
103062306a36Sopenharmony_ci		.constant		= 1,
103162306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test2_basekey,
103262306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_1byte_plaintext,
103362306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test2_confounder,
103462306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test2_expected_result,
103562306a36Sopenharmony_ci	},
103662306a36Sopenharmony_ci	{
103762306a36Sopenharmony_ci		.desc			= "Encrypt 9 bytes with camellia128-cts-cmac",
103862306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
103962306a36Sopenharmony_ci		.constant		= 2,
104062306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test3_basekey,
104162306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_9byte_plaintext,
104262306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test3_confounder,
104362306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test3_expected_result,
104462306a36Sopenharmony_ci	},
104562306a36Sopenharmony_ci	{
104662306a36Sopenharmony_ci		.desc			= "Encrypt 13 bytes with camellia128-cts-cmac",
104762306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
104862306a36Sopenharmony_ci		.constant		= 3,
104962306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test4_basekey,
105062306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_13byte_plaintext,
105162306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test4_confounder,
105262306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test4_expected_result,
105362306a36Sopenharmony_ci	},
105462306a36Sopenharmony_ci	{
105562306a36Sopenharmony_ci		.desc			= "Encrypt 30 bytes with camellia128-cts-cmac",
105662306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
105762306a36Sopenharmony_ci		.constant		= 4,
105862306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test5_basekey,
105962306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_30byte_plaintext,
106062306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test5_confounder,
106162306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test5_expected_result,
106262306a36Sopenharmony_ci	},
106362306a36Sopenharmony_ci	{
106462306a36Sopenharmony_ci		.desc			= "Encrypt empty plaintext with camellia256-cts-cmac",
106562306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
106662306a36Sopenharmony_ci		.constant		= 0,
106762306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test6_basekey,
106862306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_empty_plaintext,
106962306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test6_confounder,
107062306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test6_expected_result,
107162306a36Sopenharmony_ci	},
107262306a36Sopenharmony_ci	{
107362306a36Sopenharmony_ci		.desc			= "Encrypt 1 byte with camellia256-cts-cmac",
107462306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
107562306a36Sopenharmony_ci		.constant		= 1,
107662306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test7_basekey,
107762306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_1byte_plaintext,
107862306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test7_confounder,
107962306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test7_expected_result,
108062306a36Sopenharmony_ci	},
108162306a36Sopenharmony_ci	{
108262306a36Sopenharmony_ci		.desc			= "Encrypt 9 bytes with camellia256-cts-cmac",
108362306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
108462306a36Sopenharmony_ci		.constant		= 2,
108562306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test8_basekey,
108662306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_9byte_plaintext,
108762306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test8_confounder,
108862306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test8_expected_result,
108962306a36Sopenharmony_ci	},
109062306a36Sopenharmony_ci	{
109162306a36Sopenharmony_ci		.desc			= "Encrypt 13 bytes with camellia256-cts-cmac",
109262306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
109362306a36Sopenharmony_ci		.constant		= 3,
109462306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test9_basekey,
109562306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_13byte_plaintext,
109662306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test9_confounder,
109762306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test9_expected_result,
109862306a36Sopenharmony_ci	},
109962306a36Sopenharmony_ci	{
110062306a36Sopenharmony_ci		.desc			= "Encrypt 30 bytes with camellia256-cts-cmac",
110162306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
110262306a36Sopenharmony_ci		.constant		= 4,
110362306a36Sopenharmony_ci		.base_key		= &rfc6803_enc_test10_basekey,
110462306a36Sopenharmony_ci		.plaintext		= &rfc6803_enc_30byte_plaintext,
110562306a36Sopenharmony_ci		.confounder		= &rfc6803_enc_test10_confounder,
110662306a36Sopenharmony_ci		.expected_result	= &rfc6803_enc_test10_expected_result,
110762306a36Sopenharmony_ci	},
110862306a36Sopenharmony_ci};
110962306a36Sopenharmony_ci
111062306a36Sopenharmony_ci/* Creates the function rfc6803_encrypt_gen_params */
111162306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc6803_encrypt, rfc6803_encrypt_test_params,
111262306a36Sopenharmony_ci		  gss_krb5_get_desc);
111362306a36Sopenharmony_ci
111462306a36Sopenharmony_cistatic void rfc6803_encrypt_case(struct kunit *test)
111562306a36Sopenharmony_ci{
111662306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
111762306a36Sopenharmony_ci	struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
111862306a36Sopenharmony_ci	const struct gss_krb5_enctype *gk5e;
111962306a36Sopenharmony_ci	struct xdr_netobj Ke, Ki, checksum;
112062306a36Sopenharmony_ci	u8 usage_data[GSS_KRB5_K5CLENGTH];
112162306a36Sopenharmony_ci	struct xdr_netobj usage = {
112262306a36Sopenharmony_ci		.data = usage_data,
112362306a36Sopenharmony_ci		.len = sizeof(usage_data),
112462306a36Sopenharmony_ci	};
112562306a36Sopenharmony_ci	struct crypto_ahash *ahash_tfm;
112662306a36Sopenharmony_ci	unsigned int blocksize;
112762306a36Sopenharmony_ci	struct xdr_buf buf;
112862306a36Sopenharmony_ci	void *text;
112962306a36Sopenharmony_ci	size_t len;
113062306a36Sopenharmony_ci	u32 err;
113162306a36Sopenharmony_ci
113262306a36Sopenharmony_ci	/* Arrange */
113362306a36Sopenharmony_ci	gk5e = gss_krb5_lookup_enctype(param->enctype);
113462306a36Sopenharmony_ci	if (!gk5e)
113562306a36Sopenharmony_ci		kunit_skip(test, "Encryption type is not available");
113662306a36Sopenharmony_ci
113762306a36Sopenharmony_ci	memset(usage_data, 0, sizeof(usage_data));
113862306a36Sopenharmony_ci	usage.data[3] = param->constant;
113962306a36Sopenharmony_ci
114062306a36Sopenharmony_ci	Ke.len = gk5e->Ke_length;
114162306a36Sopenharmony_ci	Ke.data = kunit_kzalloc(test, Ke.len, GFP_KERNEL);
114262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ke.data);
114362306a36Sopenharmony_ci	usage.data[4] = KEY_USAGE_SEED_ENCRYPTION;
114462306a36Sopenharmony_ci	err = gk5e->derive_key(gk5e, param->base_key, &Ke, &usage, GFP_KERNEL);
114562306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
114662306a36Sopenharmony_ci
114762306a36Sopenharmony_ci	cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0, 0);
114862306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
114962306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cbc_tfm, Ke.data, Ke.len);
115062306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
115162306a36Sopenharmony_ci
115262306a36Sopenharmony_ci	cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0, 0);
115362306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
115462306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cts_tfm, Ke.data, Ke.len);
115562306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
115662306a36Sopenharmony_ci	blocksize = crypto_sync_skcipher_blocksize(cts_tfm);
115762306a36Sopenharmony_ci
115862306a36Sopenharmony_ci	len = param->confounder->len + param->plaintext->len + blocksize;
115962306a36Sopenharmony_ci	text = kunit_kzalloc(test, len, GFP_KERNEL);
116062306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
116162306a36Sopenharmony_ci	memcpy(text, param->confounder->data, param->confounder->len);
116262306a36Sopenharmony_ci	memcpy(text + param->confounder->len, param->plaintext->data,
116362306a36Sopenharmony_ci	       param->plaintext->len);
116462306a36Sopenharmony_ci
116562306a36Sopenharmony_ci	memset(&buf, 0, sizeof(buf));
116662306a36Sopenharmony_ci	buf.head[0].iov_base = text;
116762306a36Sopenharmony_ci	buf.head[0].iov_len = param->confounder->len + param->plaintext->len;
116862306a36Sopenharmony_ci	buf.len = buf.head[0].iov_len;
116962306a36Sopenharmony_ci
117062306a36Sopenharmony_ci	checksum.len = gk5e->cksumlength;
117162306a36Sopenharmony_ci	checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
117262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
117362306a36Sopenharmony_ci
117462306a36Sopenharmony_ci	Ki.len = gk5e->Ki_length;
117562306a36Sopenharmony_ci	Ki.data = kunit_kzalloc(test, Ki.len, GFP_KERNEL);
117662306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ki.data);
117762306a36Sopenharmony_ci	usage.data[4] = KEY_USAGE_SEED_INTEGRITY;
117862306a36Sopenharmony_ci	err = gk5e->derive_key(gk5e, param->base_key, &Ki,
117962306a36Sopenharmony_ci			       &usage, GFP_KERNEL);
118062306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
118162306a36Sopenharmony_ci	ahash_tfm = crypto_alloc_ahash(gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
118262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ahash_tfm);
118362306a36Sopenharmony_ci	err = crypto_ahash_setkey(ahash_tfm, Ki.data, Ki.len);
118462306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
118562306a36Sopenharmony_ci
118662306a36Sopenharmony_ci	/* Act */
118762306a36Sopenharmony_ci	err = gss_krb5_checksum(ahash_tfm, NULL, 0, &buf, 0, &checksum);
118862306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
118962306a36Sopenharmony_ci
119062306a36Sopenharmony_ci	err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0, &buf, NULL, NULL, 0);
119162306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
119262306a36Sopenharmony_ci
119362306a36Sopenharmony_ci	/* Assert */
119462306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test, param->expected_result->len,
119562306a36Sopenharmony_ci			    buf.len + checksum.len,
119662306a36Sopenharmony_ci			    "ciphertext length mismatch");
119762306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
119862306a36Sopenharmony_ci			    memcmp(param->expected_result->data,
119962306a36Sopenharmony_ci				   buf.head[0].iov_base, buf.len), 0,
120062306a36Sopenharmony_ci			    "encrypted result mismatch");
120162306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
120262306a36Sopenharmony_ci			    memcmp(param->expected_result->data +
120362306a36Sopenharmony_ci				   (param->expected_result->len - checksum.len),
120462306a36Sopenharmony_ci				   checksum.data, checksum.len), 0,
120562306a36Sopenharmony_ci			    "HMAC mismatch");
120662306a36Sopenharmony_ci
120762306a36Sopenharmony_ci	crypto_free_ahash(ahash_tfm);
120862306a36Sopenharmony_ci	crypto_free_sync_skcipher(cts_tfm);
120962306a36Sopenharmony_ci	crypto_free_sync_skcipher(cbc_tfm);
121062306a36Sopenharmony_ci}
121162306a36Sopenharmony_ci
121262306a36Sopenharmony_cistatic struct kunit_case rfc6803_test_cases[] = {
121362306a36Sopenharmony_ci	{
121462306a36Sopenharmony_ci		.name			= "RFC 6803 key derivation",
121562306a36Sopenharmony_ci		.run_case		= kdf_case,
121662306a36Sopenharmony_ci		.generate_params	= rfc6803_kdf_gen_params,
121762306a36Sopenharmony_ci	},
121862306a36Sopenharmony_ci	{
121962306a36Sopenharmony_ci		.name			= "RFC 6803 checksum",
122062306a36Sopenharmony_ci		.run_case		= checksum_case,
122162306a36Sopenharmony_ci		.generate_params	= rfc6803_checksum_gen_params,
122262306a36Sopenharmony_ci	},
122362306a36Sopenharmony_ci	{
122462306a36Sopenharmony_ci		.name			= "RFC 6803 encryption",
122562306a36Sopenharmony_ci		.run_case		= rfc6803_encrypt_case,
122662306a36Sopenharmony_ci		.generate_params	= rfc6803_encrypt_gen_params,
122762306a36Sopenharmony_ci	},
122862306a36Sopenharmony_ci	{}
122962306a36Sopenharmony_ci};
123062306a36Sopenharmony_ci
123162306a36Sopenharmony_cistatic struct kunit_suite rfc6803_suite = {
123262306a36Sopenharmony_ci	.name			= "RFC 6803 suite",
123362306a36Sopenharmony_ci	.test_cases		= rfc6803_test_cases,
123462306a36Sopenharmony_ci};
123562306a36Sopenharmony_ci
123662306a36Sopenharmony_ci/*
123762306a36Sopenharmony_ci * From RFC 8009 Appendix A.  Test Vectors
123862306a36Sopenharmony_ci *
123962306a36Sopenharmony_ci * Sample results for SHA-2 enctype key derivation
124062306a36Sopenharmony_ci *
124162306a36Sopenharmony_ci * This test material is copyright (c) 2016 IETF Trust and the
124262306a36Sopenharmony_ci * persons identified as the document authors.  All rights reserved.
124362306a36Sopenharmony_ci */
124462306a36Sopenharmony_ci
124562306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_basekey,
124662306a36Sopenharmony_ci		      0x37, 0x05, 0xd9, 0x60, 0x80, 0xc1, 0x77, 0x28,
124762306a36Sopenharmony_ci		      0xa0, 0xe8, 0x00, 0xea, 0xb6, 0xe0, 0xd2, 0x3c
124862306a36Sopenharmony_ci);
124962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_Kc,
125062306a36Sopenharmony_ci		      0xb3, 0x1a, 0x01, 0x8a, 0x48, 0xf5, 0x47, 0x76,
125162306a36Sopenharmony_ci		      0xf4, 0x03, 0xe9, 0xa3, 0x96, 0x32, 0x5d, 0xc3
125262306a36Sopenharmony_ci);
125362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_Ke,
125462306a36Sopenharmony_ci		      0x9b, 0x19, 0x7d, 0xd1, 0xe8, 0xc5, 0x60, 0x9d,
125562306a36Sopenharmony_ci		      0x6e, 0x67, 0xc3, 0xe3, 0x7c, 0x62, 0xc7, 0x2e
125662306a36Sopenharmony_ci);
125762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_Ki,
125862306a36Sopenharmony_ci		      0x9f, 0xda, 0x0e, 0x56, 0xab, 0x2d, 0x85, 0xe1,
125962306a36Sopenharmony_ci		      0x56, 0x9a, 0x68, 0x86, 0x96, 0xc2, 0x6a, 0x6c
126062306a36Sopenharmony_ci);
126162306a36Sopenharmony_ci
126262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_basekey,
126362306a36Sopenharmony_ci		      0x6d, 0x40, 0x4d, 0x37, 0xfa, 0xf7, 0x9f, 0x9d,
126462306a36Sopenharmony_ci		      0xf0, 0xd3, 0x35, 0x68, 0xd3, 0x20, 0x66, 0x98,
126562306a36Sopenharmony_ci		      0x00, 0xeb, 0x48, 0x36, 0x47, 0x2e, 0xa8, 0xa0,
126662306a36Sopenharmony_ci		      0x26, 0xd1, 0x6b, 0x71, 0x82, 0x46, 0x0c, 0x52
126762306a36Sopenharmony_ci);
126862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_Kc,
126962306a36Sopenharmony_ci		      0xef, 0x57, 0x18, 0xbe, 0x86, 0xcc, 0x84, 0x96,
127062306a36Sopenharmony_ci		      0x3d, 0x8b, 0xbb, 0x50, 0x31, 0xe9, 0xf5, 0xc4,
127162306a36Sopenharmony_ci		      0xba, 0x41, 0xf2, 0x8f, 0xaf, 0x69, 0xe7, 0x3d
127262306a36Sopenharmony_ci);
127362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_Ke,
127462306a36Sopenharmony_ci		      0x56, 0xab, 0x22, 0xbe, 0xe6, 0x3d, 0x82, 0xd7,
127562306a36Sopenharmony_ci		      0xbc, 0x52, 0x27, 0xf6, 0x77, 0x3f, 0x8e, 0xa7,
127662306a36Sopenharmony_ci		      0xa5, 0xeb, 0x1c, 0x82, 0x51, 0x60, 0xc3, 0x83,
127762306a36Sopenharmony_ci		      0x12, 0x98, 0x0c, 0x44, 0x2e, 0x5c, 0x7e, 0x49
127862306a36Sopenharmony_ci);
127962306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_Ki,
128062306a36Sopenharmony_ci		      0x69, 0xb1, 0x65, 0x14, 0xe3, 0xcd, 0x8e, 0x56,
128162306a36Sopenharmony_ci		      0xb8, 0x20, 0x10, 0xd5, 0xc7, 0x30, 0x12, 0xb6,
128262306a36Sopenharmony_ci		      0x22, 0xc4, 0xd0, 0x0f, 0xfc, 0x23, 0xed, 0x1f
128362306a36Sopenharmony_ci);
128462306a36Sopenharmony_ci
128562306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc8009_kdf_test_params[] = {
128662306a36Sopenharmony_ci	{
128762306a36Sopenharmony_ci		.desc			= "Derive Kc subkey for aes128-cts-hmac-sha256-128",
128862306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
128962306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
129062306a36Sopenharmony_ci		.usage			= &usage_checksum,
129162306a36Sopenharmony_ci		.expected_result	= &aes128_cts_hmac_sha256_128_Kc,
129262306a36Sopenharmony_ci	},
129362306a36Sopenharmony_ci	{
129462306a36Sopenharmony_ci		.desc			= "Derive Ke subkey for aes128-cts-hmac-sha256-128",
129562306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
129662306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
129762306a36Sopenharmony_ci		.usage			= &usage_encryption,
129862306a36Sopenharmony_ci		.expected_result	= &aes128_cts_hmac_sha256_128_Ke,
129962306a36Sopenharmony_ci	},
130062306a36Sopenharmony_ci	{
130162306a36Sopenharmony_ci		.desc			= "Derive Ki subkey for aes128-cts-hmac-sha256-128",
130262306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
130362306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
130462306a36Sopenharmony_ci		.usage			= &usage_integrity,
130562306a36Sopenharmony_ci		.expected_result	= &aes128_cts_hmac_sha256_128_Ki,
130662306a36Sopenharmony_ci	},
130762306a36Sopenharmony_ci	{
130862306a36Sopenharmony_ci		.desc			= "Derive Kc subkey for aes256-cts-hmac-sha384-192",
130962306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
131062306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
131162306a36Sopenharmony_ci		.usage			= &usage_checksum,
131262306a36Sopenharmony_ci		.expected_result	= &aes256_cts_hmac_sha384_192_Kc,
131362306a36Sopenharmony_ci	},
131462306a36Sopenharmony_ci	{
131562306a36Sopenharmony_ci		.desc			= "Derive Ke subkey for aes256-cts-hmac-sha384-192",
131662306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
131762306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
131862306a36Sopenharmony_ci		.usage			= &usage_encryption,
131962306a36Sopenharmony_ci		.expected_result	= &aes256_cts_hmac_sha384_192_Ke,
132062306a36Sopenharmony_ci	},
132162306a36Sopenharmony_ci	{
132262306a36Sopenharmony_ci		.desc			= "Derive Ki subkey for aes256-cts-hmac-sha384-192",
132362306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
132462306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
132562306a36Sopenharmony_ci		.usage			= &usage_integrity,
132662306a36Sopenharmony_ci		.expected_result	= &aes256_cts_hmac_sha384_192_Ki,
132762306a36Sopenharmony_ci	},
132862306a36Sopenharmony_ci};
132962306a36Sopenharmony_ci
133062306a36Sopenharmony_ci/* Creates the function rfc8009_kdf_gen_params */
133162306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc8009_kdf, rfc8009_kdf_test_params, gss_krb5_get_desc);
133262306a36Sopenharmony_ci
133362306a36Sopenharmony_ci/*
133462306a36Sopenharmony_ci * From RFC 8009 Appendix A.  Test Vectors
133562306a36Sopenharmony_ci *
133662306a36Sopenharmony_ci * These sample checksums use the above sample key derivation results,
133762306a36Sopenharmony_ci * including use of the same base-key and key usage values.
133862306a36Sopenharmony_ci *
133962306a36Sopenharmony_ci * This test material is copyright (c) 2016 IETF Trust and the
134062306a36Sopenharmony_ci * persons identified as the document authors.  All rights reserved.
134162306a36Sopenharmony_ci */
134262306a36Sopenharmony_ci
134362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_checksum_plaintext,
134462306a36Sopenharmony_ci		      0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
134562306a36Sopenharmony_ci		      0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
134662306a36Sopenharmony_ci		      0x10, 0x11, 0x12, 0x13, 0x14
134762306a36Sopenharmony_ci);
134862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_checksum_test1_expected_result,
134962306a36Sopenharmony_ci		      0xd7, 0x83, 0x67, 0x18, 0x66, 0x43, 0xd6, 0x7b,
135062306a36Sopenharmony_ci		      0x41, 0x1c, 0xba, 0x91, 0x39, 0xfc, 0x1d, 0xee
135162306a36Sopenharmony_ci);
135262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_checksum_test2_expected_result,
135362306a36Sopenharmony_ci		      0x45, 0xee, 0x79, 0x15, 0x67, 0xee, 0xfc, 0xa3,
135462306a36Sopenharmony_ci		      0x7f, 0x4a, 0xc1, 0xe0, 0x22, 0x2d, 0xe8, 0x0d,
135562306a36Sopenharmony_ci		      0x43, 0xc3, 0xbf, 0xa0, 0x66, 0x99, 0x67, 0x2a
135662306a36Sopenharmony_ci);
135762306a36Sopenharmony_ci
135862306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc8009_checksum_test_params[] = {
135962306a36Sopenharmony_ci	{
136062306a36Sopenharmony_ci		.desc			= "Checksum with aes128-cts-hmac-sha256-128",
136162306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
136262306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
136362306a36Sopenharmony_ci		.usage			= &usage_checksum,
136462306a36Sopenharmony_ci		.plaintext		= &rfc8009_checksum_plaintext,
136562306a36Sopenharmony_ci		.expected_result	= &rfc8009_checksum_test1_expected_result,
136662306a36Sopenharmony_ci	},
136762306a36Sopenharmony_ci	{
136862306a36Sopenharmony_ci		.desc			= "Checksum with aes256-cts-hmac-sha384-192",
136962306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
137062306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
137162306a36Sopenharmony_ci		.usage			= &usage_checksum,
137262306a36Sopenharmony_ci		.plaintext		= &rfc8009_checksum_plaintext,
137362306a36Sopenharmony_ci		.expected_result	= &rfc8009_checksum_test2_expected_result,
137462306a36Sopenharmony_ci	},
137562306a36Sopenharmony_ci};
137662306a36Sopenharmony_ci
137762306a36Sopenharmony_ci/* Creates the function rfc8009_checksum_gen_params */
137862306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc8009_checksum, rfc8009_checksum_test_params,
137962306a36Sopenharmony_ci		  gss_krb5_get_desc);
138062306a36Sopenharmony_ci
138162306a36Sopenharmony_ci/*
138262306a36Sopenharmony_ci * From RFC 8009 Appendix A.  Test Vectors
138362306a36Sopenharmony_ci *
138462306a36Sopenharmony_ci * Sample encryptions (all using the default cipher state):
138562306a36Sopenharmony_ci * --------------------------------------------------------
138662306a36Sopenharmony_ci *
138762306a36Sopenharmony_ci * These sample encryptions use the above sample key derivation results,
138862306a36Sopenharmony_ci * including use of the same base-key and key usage values.
138962306a36Sopenharmony_ci *
139062306a36Sopenharmony_ci * This test material is copyright (c) 2016 IETF Trust and the
139162306a36Sopenharmony_ci * persons identified as the document authors.  All rights reserved.
139262306a36Sopenharmony_ci */
139362306a36Sopenharmony_ci
139462306a36Sopenharmony_cistatic const struct xdr_netobj rfc8009_enc_empty_plaintext = {
139562306a36Sopenharmony_ci	.len	= 0,
139662306a36Sopenharmony_ci};
139762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_short_plaintext,
139862306a36Sopenharmony_ci		      0x00, 0x01, 0x02, 0x03, 0x04, 0x05
139962306a36Sopenharmony_ci);
140062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_block_plaintext,
140162306a36Sopenharmony_ci		      0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
140262306a36Sopenharmony_ci		      0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
140362306a36Sopenharmony_ci);
140462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_long_plaintext,
140562306a36Sopenharmony_ci		      0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
140662306a36Sopenharmony_ci		      0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
140762306a36Sopenharmony_ci		      0x10, 0x11, 0x12, 0x13, 0x14
140862306a36Sopenharmony_ci);
140962306a36Sopenharmony_ci
141062306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test1_confounder,
141162306a36Sopenharmony_ci		      0x7e, 0x58, 0x95, 0xea, 0xf2, 0x67, 0x24, 0x35,
141262306a36Sopenharmony_ci		      0xba, 0xd8, 0x17, 0xf5, 0x45, 0xa3, 0x71, 0x48
141362306a36Sopenharmony_ci);
141462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test1_expected_result,
141562306a36Sopenharmony_ci		      0xef, 0x85, 0xfb, 0x89, 0x0b, 0xb8, 0x47, 0x2f,
141662306a36Sopenharmony_ci		      0x4d, 0xab, 0x20, 0x39, 0x4d, 0xca, 0x78, 0x1d
141762306a36Sopenharmony_ci);
141862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test1_expected_hmac,
141962306a36Sopenharmony_ci		      0xad, 0x87, 0x7e, 0xda, 0x39, 0xd5, 0x0c, 0x87,
142062306a36Sopenharmony_ci		      0x0c, 0x0d, 0x5a, 0x0a, 0x8e, 0x48, 0xc7, 0x18
142162306a36Sopenharmony_ci);
142262306a36Sopenharmony_ci
142362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test2_confounder,
142462306a36Sopenharmony_ci		      0x7b, 0xca, 0x28, 0x5e, 0x2f, 0xd4, 0x13, 0x0f,
142562306a36Sopenharmony_ci		      0xb5, 0x5b, 0x1a, 0x5c, 0x83, 0xbc, 0x5b, 0x24
142662306a36Sopenharmony_ci);
142762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test2_expected_result,
142862306a36Sopenharmony_ci		      0x84, 0xd7, 0xf3, 0x07, 0x54, 0xed, 0x98, 0x7b,
142962306a36Sopenharmony_ci		      0xab, 0x0b, 0xf3, 0x50, 0x6b, 0xeb, 0x09, 0xcf,
143062306a36Sopenharmony_ci		      0xb5, 0x54, 0x02, 0xce, 0xf7, 0xe6
143162306a36Sopenharmony_ci);
143262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test2_expected_hmac,
143362306a36Sopenharmony_ci		      0x87, 0x7c, 0xe9, 0x9e, 0x24, 0x7e, 0x52, 0xd1,
143462306a36Sopenharmony_ci		      0x6e, 0xd4, 0x42, 0x1d, 0xfd, 0xf8, 0x97, 0x6c
143562306a36Sopenharmony_ci);
143662306a36Sopenharmony_ci
143762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test3_confounder,
143862306a36Sopenharmony_ci		      0x56, 0xab, 0x21, 0x71, 0x3f, 0xf6, 0x2c, 0x0a,
143962306a36Sopenharmony_ci		      0x14, 0x57, 0x20, 0x0f, 0x6f, 0xa9, 0x94, 0x8f
144062306a36Sopenharmony_ci);
144162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test3_expected_result,
144262306a36Sopenharmony_ci		      0x35, 0x17, 0xd6, 0x40, 0xf5, 0x0d, 0xdc, 0x8a,
144362306a36Sopenharmony_ci		      0xd3, 0x62, 0x87, 0x22, 0xb3, 0x56, 0x9d, 0x2a,
144462306a36Sopenharmony_ci		      0xe0, 0x74, 0x93, 0xfa, 0x82, 0x63, 0x25, 0x40,
144562306a36Sopenharmony_ci		      0x80, 0xea, 0x65, 0xc1, 0x00, 0x8e, 0x8f, 0xc2
144662306a36Sopenharmony_ci);
144762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test3_expected_hmac,
144862306a36Sopenharmony_ci		      0x95, 0xfb, 0x48, 0x52, 0xe7, 0xd8, 0x3e, 0x1e,
144962306a36Sopenharmony_ci		      0x7c, 0x48, 0xc3, 0x7e, 0xeb, 0xe6, 0xb0, 0xd3
145062306a36Sopenharmony_ci);
145162306a36Sopenharmony_ci
145262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test4_confounder,
145362306a36Sopenharmony_ci		      0xa7, 0xa4, 0xe2, 0x9a, 0x47, 0x28, 0xce, 0x10,
145462306a36Sopenharmony_ci		      0x66, 0x4f, 0xb6, 0x4e, 0x49, 0xad, 0x3f, 0xac
145562306a36Sopenharmony_ci);
145662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test4_expected_result,
145762306a36Sopenharmony_ci		      0x72, 0x0f, 0x73, 0xb1, 0x8d, 0x98, 0x59, 0xcd,
145862306a36Sopenharmony_ci		      0x6c, 0xcb, 0x43, 0x46, 0x11, 0x5c, 0xd3, 0x36,
145962306a36Sopenharmony_ci		      0xc7, 0x0f, 0x58, 0xed, 0xc0, 0xc4, 0x43, 0x7c,
146062306a36Sopenharmony_ci		      0x55, 0x73, 0x54, 0x4c, 0x31, 0xc8, 0x13, 0xbc,
146162306a36Sopenharmony_ci		      0xe1, 0xe6, 0xd0, 0x72, 0xc1
146262306a36Sopenharmony_ci);
146362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test4_expected_hmac,
146462306a36Sopenharmony_ci		      0x86, 0xb3, 0x9a, 0x41, 0x3c, 0x2f, 0x92, 0xca,
146562306a36Sopenharmony_ci		      0x9b, 0x83, 0x34, 0xa2, 0x87, 0xff, 0xcb, 0xfc
146662306a36Sopenharmony_ci);
146762306a36Sopenharmony_ci
146862306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test5_confounder,
146962306a36Sopenharmony_ci		      0xf7, 0x64, 0xe9, 0xfa, 0x15, 0xc2, 0x76, 0x47,
147062306a36Sopenharmony_ci		      0x8b, 0x2c, 0x7d, 0x0c, 0x4e, 0x5f, 0x58, 0xe4
147162306a36Sopenharmony_ci);
147262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test5_expected_result,
147362306a36Sopenharmony_ci		      0x41, 0xf5, 0x3f, 0xa5, 0xbf, 0xe7, 0x02, 0x6d,
147462306a36Sopenharmony_ci		      0x91, 0xfa, 0xf9, 0xbe, 0x95, 0x91, 0x95, 0xa0
147562306a36Sopenharmony_ci);
147662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test5_expected_hmac,
147762306a36Sopenharmony_ci		      0x58, 0x70, 0x72, 0x73, 0xa9, 0x6a, 0x40, 0xf0,
147862306a36Sopenharmony_ci		      0xa0, 0x19, 0x60, 0x62, 0x1a, 0xc6, 0x12, 0x74,
147962306a36Sopenharmony_ci		      0x8b, 0x9b, 0xbf, 0xbe, 0x7e, 0xb4, 0xce, 0x3c
148062306a36Sopenharmony_ci);
148162306a36Sopenharmony_ci
148262306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test6_confounder,
148362306a36Sopenharmony_ci		      0xb8, 0x0d, 0x32, 0x51, 0xc1, 0xf6, 0x47, 0x14,
148462306a36Sopenharmony_ci		      0x94, 0x25, 0x6f, 0xfe, 0x71, 0x2d, 0x0b, 0x9a
148562306a36Sopenharmony_ci);
148662306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test6_expected_result,
148762306a36Sopenharmony_ci		      0x4e, 0xd7, 0xb3, 0x7c, 0x2b, 0xca, 0xc8, 0xf7,
148862306a36Sopenharmony_ci		      0x4f, 0x23, 0xc1, 0xcf, 0x07, 0xe6, 0x2b, 0xc7,
148962306a36Sopenharmony_ci		      0xb7, 0x5f, 0xb3, 0xf6, 0x37, 0xb9
149062306a36Sopenharmony_ci);
149162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test6_expected_hmac,
149262306a36Sopenharmony_ci		      0xf5, 0x59, 0xc7, 0xf6, 0x64, 0xf6, 0x9e, 0xab,
149362306a36Sopenharmony_ci		      0x7b, 0x60, 0x92, 0x23, 0x75, 0x26, 0xea, 0x0d,
149462306a36Sopenharmony_ci		      0x1f, 0x61, 0xcb, 0x20, 0xd6, 0x9d, 0x10, 0xf2
149562306a36Sopenharmony_ci);
149662306a36Sopenharmony_ci
149762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test7_confounder,
149862306a36Sopenharmony_ci		      0x53, 0xbf, 0x8a, 0x0d, 0x10, 0x52, 0x65, 0xd4,
149962306a36Sopenharmony_ci		      0xe2, 0x76, 0x42, 0x86, 0x24, 0xce, 0x5e, 0x63
150062306a36Sopenharmony_ci);
150162306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test7_expected_result,
150262306a36Sopenharmony_ci		      0xbc, 0x47, 0xff, 0xec, 0x79, 0x98, 0xeb, 0x91,
150362306a36Sopenharmony_ci		      0xe8, 0x11, 0x5c, 0xf8, 0xd1, 0x9d, 0xac, 0x4b,
150462306a36Sopenharmony_ci		      0xbb, 0xe2, 0xe1, 0x63, 0xe8, 0x7d, 0xd3, 0x7f,
150562306a36Sopenharmony_ci		      0x49, 0xbe, 0xca, 0x92, 0x02, 0x77, 0x64, 0xf6
150662306a36Sopenharmony_ci);
150762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test7_expected_hmac,
150862306a36Sopenharmony_ci		      0x8c, 0xf5, 0x1f, 0x14, 0xd7, 0x98, 0xc2, 0x27,
150962306a36Sopenharmony_ci		      0x3f, 0x35, 0xdf, 0x57, 0x4d, 0x1f, 0x93, 0x2e,
151062306a36Sopenharmony_ci		      0x40, 0xc4, 0xff, 0x25, 0x5b, 0x36, 0xa2, 0x66
151162306a36Sopenharmony_ci);
151262306a36Sopenharmony_ci
151362306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test8_confounder,
151462306a36Sopenharmony_ci		      0x76, 0x3e, 0x65, 0x36, 0x7e, 0x86, 0x4f, 0x02,
151562306a36Sopenharmony_ci		      0xf5, 0x51, 0x53, 0xc7, 0xe3, 0xb5, 0x8a, 0xf1
151662306a36Sopenharmony_ci);
151762306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test8_expected_result,
151862306a36Sopenharmony_ci		      0x40, 0x01, 0x3e, 0x2d, 0xf5, 0x8e, 0x87, 0x51,
151962306a36Sopenharmony_ci		      0x95, 0x7d, 0x28, 0x78, 0xbc, 0xd2, 0xd6, 0xfe,
152062306a36Sopenharmony_ci		      0x10, 0x1c, 0xcf, 0xd5, 0x56, 0xcb, 0x1e, 0xae,
152162306a36Sopenharmony_ci		      0x79, 0xdb, 0x3c, 0x3e, 0xe8, 0x64, 0x29, 0xf2,
152262306a36Sopenharmony_ci		      0xb2, 0xa6, 0x02, 0xac, 0x86
152362306a36Sopenharmony_ci);
152462306a36Sopenharmony_ciDEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test8_expected_hmac,
152562306a36Sopenharmony_ci		      0xfe, 0xf6, 0xec, 0xb6, 0x47, 0xd6, 0x29, 0x5f,
152662306a36Sopenharmony_ci		      0xae, 0x07, 0x7a, 0x1f, 0xeb, 0x51, 0x75, 0x08,
152762306a36Sopenharmony_ci		      0xd2, 0xc1, 0x6b, 0x41, 0x92, 0xe0, 0x1f, 0x62
152862306a36Sopenharmony_ci);
152962306a36Sopenharmony_ci
153062306a36Sopenharmony_cistatic const struct gss_krb5_test_param rfc8009_encrypt_test_params[] = {
153162306a36Sopenharmony_ci	{
153262306a36Sopenharmony_ci		.desc			= "Encrypt empty plaintext with aes128-cts-hmac-sha256-128",
153362306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
153462306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_empty_plaintext,
153562306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test1_confounder,
153662306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
153762306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test1_expected_result,
153862306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test1_expected_hmac,
153962306a36Sopenharmony_ci	},
154062306a36Sopenharmony_ci	{
154162306a36Sopenharmony_ci		.desc			= "Encrypt short plaintext with aes128-cts-hmac-sha256-128",
154262306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
154362306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_short_plaintext,
154462306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test2_confounder,
154562306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
154662306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test2_expected_result,
154762306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test2_expected_hmac,
154862306a36Sopenharmony_ci	},
154962306a36Sopenharmony_ci	{
155062306a36Sopenharmony_ci		.desc			= "Encrypt block plaintext with aes128-cts-hmac-sha256-128",
155162306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
155262306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_block_plaintext,
155362306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test3_confounder,
155462306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
155562306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test3_expected_result,
155662306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test3_expected_hmac,
155762306a36Sopenharmony_ci	},
155862306a36Sopenharmony_ci	{
155962306a36Sopenharmony_ci		.desc			= "Encrypt long plaintext with aes128-cts-hmac-sha256-128",
156062306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
156162306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_long_plaintext,
156262306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test4_confounder,
156362306a36Sopenharmony_ci		.base_key		= &aes128_cts_hmac_sha256_128_basekey,
156462306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test4_expected_result,
156562306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test4_expected_hmac,
156662306a36Sopenharmony_ci	},
156762306a36Sopenharmony_ci	{
156862306a36Sopenharmony_ci		.desc			= "Encrypt empty plaintext with aes256-cts-hmac-sha384-192",
156962306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
157062306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_empty_plaintext,
157162306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test5_confounder,
157262306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
157362306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test5_expected_result,
157462306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test5_expected_hmac,
157562306a36Sopenharmony_ci	},
157662306a36Sopenharmony_ci	{
157762306a36Sopenharmony_ci		.desc			= "Encrypt short plaintext with aes256-cts-hmac-sha384-192",
157862306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
157962306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_short_plaintext,
158062306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test6_confounder,
158162306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
158262306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test6_expected_result,
158362306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test6_expected_hmac,
158462306a36Sopenharmony_ci	},
158562306a36Sopenharmony_ci	{
158662306a36Sopenharmony_ci		.desc			= "Encrypt block plaintext with aes256-cts-hmac-sha384-192",
158762306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
158862306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_block_plaintext,
158962306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test7_confounder,
159062306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
159162306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test7_expected_result,
159262306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test7_expected_hmac,
159362306a36Sopenharmony_ci	},
159462306a36Sopenharmony_ci	{
159562306a36Sopenharmony_ci		.desc			= "Encrypt long plaintext with aes256-cts-hmac-sha384-192",
159662306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
159762306a36Sopenharmony_ci		.plaintext		= &rfc8009_enc_long_plaintext,
159862306a36Sopenharmony_ci		.confounder		= &rfc8009_enc_test8_confounder,
159962306a36Sopenharmony_ci		.base_key		= &aes256_cts_hmac_sha384_192_basekey,
160062306a36Sopenharmony_ci		.expected_result	= &rfc8009_enc_test8_expected_result,
160162306a36Sopenharmony_ci		.expected_hmac		= &rfc8009_enc_test8_expected_hmac,
160262306a36Sopenharmony_ci	},
160362306a36Sopenharmony_ci};
160462306a36Sopenharmony_ci
160562306a36Sopenharmony_ci/* Creates the function rfc8009_encrypt_gen_params */
160662306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(rfc8009_encrypt, rfc8009_encrypt_test_params,
160762306a36Sopenharmony_ci		  gss_krb5_get_desc);
160862306a36Sopenharmony_ci
160962306a36Sopenharmony_cistatic void rfc8009_encrypt_case(struct kunit *test)
161062306a36Sopenharmony_ci{
161162306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
161262306a36Sopenharmony_ci	struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
161362306a36Sopenharmony_ci	const struct gss_krb5_enctype *gk5e;
161462306a36Sopenharmony_ci	struct xdr_netobj Ke, Ki, checksum;
161562306a36Sopenharmony_ci	u8 usage_data[GSS_KRB5_K5CLENGTH];
161662306a36Sopenharmony_ci	struct xdr_netobj usage = {
161762306a36Sopenharmony_ci		.data = usage_data,
161862306a36Sopenharmony_ci		.len = sizeof(usage_data),
161962306a36Sopenharmony_ci	};
162062306a36Sopenharmony_ci	struct crypto_ahash *ahash_tfm;
162162306a36Sopenharmony_ci	struct xdr_buf buf;
162262306a36Sopenharmony_ci	void *text;
162362306a36Sopenharmony_ci	size_t len;
162462306a36Sopenharmony_ci	u32 err;
162562306a36Sopenharmony_ci
162662306a36Sopenharmony_ci	/* Arrange */
162762306a36Sopenharmony_ci	gk5e = gss_krb5_lookup_enctype(param->enctype);
162862306a36Sopenharmony_ci	if (!gk5e)
162962306a36Sopenharmony_ci		kunit_skip(test, "Encryption type is not available");
163062306a36Sopenharmony_ci
163162306a36Sopenharmony_ci	*(__be32 *)usage.data = cpu_to_be32(2);
163262306a36Sopenharmony_ci
163362306a36Sopenharmony_ci	Ke.len = gk5e->Ke_length;
163462306a36Sopenharmony_ci	Ke.data = kunit_kzalloc(test, Ke.len, GFP_KERNEL);
163562306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ke.data);
163662306a36Sopenharmony_ci	usage.data[4] = KEY_USAGE_SEED_ENCRYPTION;
163762306a36Sopenharmony_ci	err = gk5e->derive_key(gk5e, param->base_key, &Ke,
163862306a36Sopenharmony_ci			       &usage, GFP_KERNEL);
163962306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
164062306a36Sopenharmony_ci
164162306a36Sopenharmony_ci	cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0, 0);
164262306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
164362306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cbc_tfm, Ke.data, Ke.len);
164462306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
164562306a36Sopenharmony_ci
164662306a36Sopenharmony_ci	cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0, 0);
164762306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
164862306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cts_tfm, Ke.data, Ke.len);
164962306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
165062306a36Sopenharmony_ci
165162306a36Sopenharmony_ci	len = param->confounder->len + param->plaintext->len;
165262306a36Sopenharmony_ci	text = kunit_kzalloc(test, len, GFP_KERNEL);
165362306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
165462306a36Sopenharmony_ci	memcpy(text, param->confounder->data, param->confounder->len);
165562306a36Sopenharmony_ci	memcpy(text + param->confounder->len, param->plaintext->data,
165662306a36Sopenharmony_ci	       param->plaintext->len);
165762306a36Sopenharmony_ci
165862306a36Sopenharmony_ci	memset(&buf, 0, sizeof(buf));
165962306a36Sopenharmony_ci	buf.head[0].iov_base = text;
166062306a36Sopenharmony_ci	buf.head[0].iov_len = param->confounder->len + param->plaintext->len;
166162306a36Sopenharmony_ci	buf.len = buf.head[0].iov_len;
166262306a36Sopenharmony_ci
166362306a36Sopenharmony_ci	checksum.len = gk5e->cksumlength;
166462306a36Sopenharmony_ci	checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
166562306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
166662306a36Sopenharmony_ci
166762306a36Sopenharmony_ci	Ki.len = gk5e->Ki_length;
166862306a36Sopenharmony_ci	Ki.data = kunit_kzalloc(test, Ki.len, GFP_KERNEL);
166962306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ki.data);
167062306a36Sopenharmony_ci	usage.data[4] = KEY_USAGE_SEED_INTEGRITY;
167162306a36Sopenharmony_ci	err = gk5e->derive_key(gk5e, param->base_key, &Ki,
167262306a36Sopenharmony_ci			       &usage, GFP_KERNEL);
167362306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
167462306a36Sopenharmony_ci
167562306a36Sopenharmony_ci	ahash_tfm = crypto_alloc_ahash(gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
167662306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ahash_tfm);
167762306a36Sopenharmony_ci	err = crypto_ahash_setkey(ahash_tfm, Ki.data, Ki.len);
167862306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
167962306a36Sopenharmony_ci
168062306a36Sopenharmony_ci	/* Act */
168162306a36Sopenharmony_ci	err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0, &buf, NULL, NULL, 0);
168262306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
168362306a36Sopenharmony_ci	err = krb5_etm_checksum(cts_tfm, ahash_tfm, &buf, 0, &checksum);
168462306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
168562306a36Sopenharmony_ci
168662306a36Sopenharmony_ci	/* Assert */
168762306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
168862306a36Sopenharmony_ci			    param->expected_result->len, buf.len,
168962306a36Sopenharmony_ci			    "ciphertext length mismatch");
169062306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
169162306a36Sopenharmony_ci			    memcmp(param->expected_result->data,
169262306a36Sopenharmony_ci				   buf.head[0].iov_base,
169362306a36Sopenharmony_ci				   param->expected_result->len), 0,
169462306a36Sopenharmony_ci			    "ciphertext mismatch");
169562306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test, memcmp(param->expected_hmac->data,
169662306a36Sopenharmony_ci					 checksum.data,
169762306a36Sopenharmony_ci					 checksum.len), 0,
169862306a36Sopenharmony_ci			    "HMAC mismatch");
169962306a36Sopenharmony_ci
170062306a36Sopenharmony_ci	crypto_free_ahash(ahash_tfm);
170162306a36Sopenharmony_ci	crypto_free_sync_skcipher(cts_tfm);
170262306a36Sopenharmony_ci	crypto_free_sync_skcipher(cbc_tfm);
170362306a36Sopenharmony_ci}
170462306a36Sopenharmony_ci
170562306a36Sopenharmony_cistatic struct kunit_case rfc8009_test_cases[] = {
170662306a36Sopenharmony_ci	{
170762306a36Sopenharmony_ci		.name			= "RFC 8009 key derivation",
170862306a36Sopenharmony_ci		.run_case		= kdf_case,
170962306a36Sopenharmony_ci		.generate_params	= rfc8009_kdf_gen_params,
171062306a36Sopenharmony_ci	},
171162306a36Sopenharmony_ci	{
171262306a36Sopenharmony_ci		.name			= "RFC 8009 checksum",
171362306a36Sopenharmony_ci		.run_case		= checksum_case,
171462306a36Sopenharmony_ci		.generate_params	= rfc8009_checksum_gen_params,
171562306a36Sopenharmony_ci	},
171662306a36Sopenharmony_ci	{
171762306a36Sopenharmony_ci		.name			= "RFC 8009 encryption",
171862306a36Sopenharmony_ci		.run_case		= rfc8009_encrypt_case,
171962306a36Sopenharmony_ci		.generate_params	= rfc8009_encrypt_gen_params,
172062306a36Sopenharmony_ci	},
172162306a36Sopenharmony_ci	{}
172262306a36Sopenharmony_ci};
172362306a36Sopenharmony_ci
172462306a36Sopenharmony_cistatic struct kunit_suite rfc8009_suite = {
172562306a36Sopenharmony_ci	.name			= "RFC 8009 suite",
172662306a36Sopenharmony_ci	.test_cases		= rfc8009_test_cases,
172762306a36Sopenharmony_ci};
172862306a36Sopenharmony_ci
172962306a36Sopenharmony_ci/*
173062306a36Sopenharmony_ci * Encryption self-tests
173162306a36Sopenharmony_ci */
173262306a36Sopenharmony_ci
173362306a36Sopenharmony_ciDEFINE_STR_XDR_NETOBJ(encrypt_selftest_plaintext,
173462306a36Sopenharmony_ci		      "This is the plaintext for the encryption self-test.");
173562306a36Sopenharmony_ci
173662306a36Sopenharmony_cistatic const struct gss_krb5_test_param encrypt_selftest_params[] = {
173762306a36Sopenharmony_ci	{
173862306a36Sopenharmony_ci		.desc			= "aes128-cts-hmac-sha1-96 encryption self-test",
173962306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA1_96,
174062306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
174162306a36Sopenharmony_ci		.plaintext		= &encrypt_selftest_plaintext,
174262306a36Sopenharmony_ci	},
174362306a36Sopenharmony_ci	{
174462306a36Sopenharmony_ci		.desc			= "aes256-cts-hmac-sha1-96 encryption self-test",
174562306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA1_96,
174662306a36Sopenharmony_ci		.Ke			= &rfc3962_encryption_key,
174762306a36Sopenharmony_ci		.plaintext		= &encrypt_selftest_plaintext,
174862306a36Sopenharmony_ci	},
174962306a36Sopenharmony_ci	{
175062306a36Sopenharmony_ci		.desc			= "camellia128-cts-cmac encryption self-test",
175162306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA128_CTS_CMAC,
175262306a36Sopenharmony_ci		.Ke			= &camellia128_cts_cmac_Ke,
175362306a36Sopenharmony_ci		.plaintext		= &encrypt_selftest_plaintext,
175462306a36Sopenharmony_ci	},
175562306a36Sopenharmony_ci	{
175662306a36Sopenharmony_ci		.desc			= "camellia256-cts-cmac encryption self-test",
175762306a36Sopenharmony_ci		.enctype		= ENCTYPE_CAMELLIA256_CTS_CMAC,
175862306a36Sopenharmony_ci		.Ke			= &camellia256_cts_cmac_Ke,
175962306a36Sopenharmony_ci		.plaintext		= &encrypt_selftest_plaintext,
176062306a36Sopenharmony_ci	},
176162306a36Sopenharmony_ci	{
176262306a36Sopenharmony_ci		.desc			= "aes128-cts-hmac-sha256-128 encryption self-test",
176362306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES128_CTS_HMAC_SHA256_128,
176462306a36Sopenharmony_ci		.Ke			= &aes128_cts_hmac_sha256_128_Ke,
176562306a36Sopenharmony_ci		.plaintext		= &encrypt_selftest_plaintext,
176662306a36Sopenharmony_ci	},
176762306a36Sopenharmony_ci	{
176862306a36Sopenharmony_ci		.desc			= "aes256-cts-hmac-sha384-192 encryption self-test",
176962306a36Sopenharmony_ci		.enctype		= ENCTYPE_AES256_CTS_HMAC_SHA384_192,
177062306a36Sopenharmony_ci		.Ke			= &aes256_cts_hmac_sha384_192_Ke,
177162306a36Sopenharmony_ci		.plaintext		= &encrypt_selftest_plaintext,
177262306a36Sopenharmony_ci	},
177362306a36Sopenharmony_ci};
177462306a36Sopenharmony_ci
177562306a36Sopenharmony_ci/* Creates the function encrypt_selftest_gen_params */
177662306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(encrypt_selftest, encrypt_selftest_params,
177762306a36Sopenharmony_ci		  gss_krb5_get_desc);
177862306a36Sopenharmony_ci
177962306a36Sopenharmony_ci/*
178062306a36Sopenharmony_ci * Encrypt and decrypt plaintext, and ensure the input plaintext
178162306a36Sopenharmony_ci * matches the output plaintext. A confounder is not added in this
178262306a36Sopenharmony_ci * case.
178362306a36Sopenharmony_ci */
178462306a36Sopenharmony_cistatic void encrypt_selftest_case(struct kunit *test)
178562306a36Sopenharmony_ci{
178662306a36Sopenharmony_ci	const struct gss_krb5_test_param *param = test->param_value;
178762306a36Sopenharmony_ci	struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
178862306a36Sopenharmony_ci	const struct gss_krb5_enctype *gk5e;
178962306a36Sopenharmony_ci	struct xdr_buf buf;
179062306a36Sopenharmony_ci	void *text;
179162306a36Sopenharmony_ci	int err;
179262306a36Sopenharmony_ci
179362306a36Sopenharmony_ci	/* Arrange */
179462306a36Sopenharmony_ci	gk5e = gss_krb5_lookup_enctype(param->enctype);
179562306a36Sopenharmony_ci	if (!gk5e)
179662306a36Sopenharmony_ci		kunit_skip(test, "Encryption type is not available");
179762306a36Sopenharmony_ci
179862306a36Sopenharmony_ci	cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0, 0);
179962306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
180062306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cbc_tfm, param->Ke->data, param->Ke->len);
180162306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
180262306a36Sopenharmony_ci
180362306a36Sopenharmony_ci	cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0, 0);
180462306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
180562306a36Sopenharmony_ci	err = crypto_sync_skcipher_setkey(cts_tfm, param->Ke->data, param->Ke->len);
180662306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
180762306a36Sopenharmony_ci
180862306a36Sopenharmony_ci	text = kunit_kzalloc(test, roundup(param->plaintext->len,
180962306a36Sopenharmony_ci					   crypto_sync_skcipher_blocksize(cbc_tfm)),
181062306a36Sopenharmony_ci			     GFP_KERNEL);
181162306a36Sopenharmony_ci	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
181262306a36Sopenharmony_ci
181362306a36Sopenharmony_ci	memcpy(text, param->plaintext->data, param->plaintext->len);
181462306a36Sopenharmony_ci	memset(&buf, 0, sizeof(buf));
181562306a36Sopenharmony_ci	buf.head[0].iov_base = text;
181662306a36Sopenharmony_ci	buf.head[0].iov_len = param->plaintext->len;
181762306a36Sopenharmony_ci	buf.len = buf.head[0].iov_len;
181862306a36Sopenharmony_ci
181962306a36Sopenharmony_ci	/* Act */
182062306a36Sopenharmony_ci	err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0, &buf, NULL, NULL, 0);
182162306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
182262306a36Sopenharmony_ci	err = krb5_cbc_cts_decrypt(cts_tfm, cbc_tfm, 0, &buf);
182362306a36Sopenharmony_ci	KUNIT_ASSERT_EQ(test, err, 0);
182462306a36Sopenharmony_ci
182562306a36Sopenharmony_ci	/* Assert */
182662306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
182762306a36Sopenharmony_ci			    param->plaintext->len, buf.len,
182862306a36Sopenharmony_ci			    "length mismatch");
182962306a36Sopenharmony_ci	KUNIT_EXPECT_EQ_MSG(test,
183062306a36Sopenharmony_ci			    memcmp(param->plaintext->data,
183162306a36Sopenharmony_ci				   buf.head[0].iov_base, buf.len), 0,
183262306a36Sopenharmony_ci			    "plaintext mismatch");
183362306a36Sopenharmony_ci
183462306a36Sopenharmony_ci	crypto_free_sync_skcipher(cts_tfm);
183562306a36Sopenharmony_ci	crypto_free_sync_skcipher(cbc_tfm);
183662306a36Sopenharmony_ci}
183762306a36Sopenharmony_ci
183862306a36Sopenharmony_cistatic struct kunit_case encryption_test_cases[] = {
183962306a36Sopenharmony_ci	{
184062306a36Sopenharmony_ci		.name			= "Encryption self-tests",
184162306a36Sopenharmony_ci		.run_case		= encrypt_selftest_case,
184262306a36Sopenharmony_ci		.generate_params	= encrypt_selftest_gen_params,
184362306a36Sopenharmony_ci	},
184462306a36Sopenharmony_ci	{}
184562306a36Sopenharmony_ci};
184662306a36Sopenharmony_ci
184762306a36Sopenharmony_cistatic struct kunit_suite encryption_test_suite = {
184862306a36Sopenharmony_ci	.name			= "Encryption test suite",
184962306a36Sopenharmony_ci	.test_cases		= encryption_test_cases,
185062306a36Sopenharmony_ci};
185162306a36Sopenharmony_ci
185262306a36Sopenharmony_cikunit_test_suites(&rfc3961_suite,
185362306a36Sopenharmony_ci		  &rfc3962_suite,
185462306a36Sopenharmony_ci		  &rfc6803_suite,
185562306a36Sopenharmony_ci		  &rfc8009_suite,
185662306a36Sopenharmony_ci		  &encryption_test_suite);
185762306a36Sopenharmony_ci
185862306a36Sopenharmony_ciMODULE_DESCRIPTION("Test RPCSEC GSS Kerberos 5 functions");
185962306a36Sopenharmony_ciMODULE_LICENSE("GPL");
1860