// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
*
* KUnit test of SunRPC's GSS Kerberos mechanism. Subsystem
* name is "rpcsec_gss_krb5".
*/
#include <kunit/test.h>
#include <kunit/visibility.h>
#include <linux/kernel.h>
#include <crypto/hash.h>
#include <linux/sunrpc/xdr.h>
#include <linux/sunrpc/gss_krb5.h>
#include "gss_krb5_internal.h"
MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING" );
struct gss_krb5_test_param {
const char *desc;
u32 enctype;
u32 nfold;
u32 constant;
const struct xdr_netobj *base_key;
const struct xdr_netobj *Ke;
const struct xdr_netobj *usage;
const struct xdr_netobj *plaintext;
const struct xdr_netobj *confounder;
const struct xdr_netobj *expected_result;
const struct xdr_netobj *expected_hmac;
const struct xdr_netobj *next_iv;
};
static inline void gss_krb5_get_desc(const struct gss_krb5_test_param *param,
char *desc)
{
strscpy(desc, param->desc, KUNIT_PARAM_DESC_SIZE);
}
static void kdf_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
const struct gss_krb5_enctype *gk5e;
struct xdr_netobj derivedkey;
int err;
/* Arrange */
gk5e = gss_krb5_lookup_enctype(param->enctype);
if (!gk5e)
kunit_skip(test, "Encryption type is not available" );
derivedkey.data = kunit_kzalloc(test, param->expected_result->len,
GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, derivedkey.data);
derivedkey.len = param->expected_result->len;
/* Act */
err = gk5e->derive_key(gk5e, param->base_key, &derivedkey,
param->usage, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0 );
/* Assert */
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data,
derivedkey.data, derivedkey.len), 0 ,
"key mismatch" );
}
static void checksum_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
struct xdr_buf buf = {
.head[0 ].iov_len = param->plaintext->len,
.len = param->plaintext->len,
};
const struct gss_krb5_enctype *gk5e;
struct xdr_netobj Kc, checksum;
struct crypto_ahash *tfm;
int err;
/* Arrange */
gk5e = gss_krb5_lookup_enctype(param->enctype);
if (!gk5e)
kunit_skip(test, "Encryption type is not available" );
Kc.len = gk5e->Kc_length;
Kc.data = kunit_kzalloc(test, Kc.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Kc.data);
err = gk5e->derive_key(gk5e, param->base_key, &Kc,
param->usage, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0 );
tfm = crypto_alloc_ahash(gk5e->cksum_name, 0 , CRYPTO_ALG_ASYNC);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, tfm);
err = crypto_ahash_setkey(tfm, Kc.data, Kc.len);
KUNIT_ASSERT_EQ(test, err, 0 );
buf.head[0 ].iov_base = kunit_kzalloc(test, buf.head[0 ].iov_len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf.head[0 ].iov_base);
memcpy(buf.head[0 ].iov_base, param->plaintext->data, buf.head[0 ].iov_len);
checksum.len = gk5e->cksumlength;
checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
/* Act */
err = gss_krb5_checksum(tfm, NULL, 0 , &buf, 0 , &checksum);
KUNIT_ASSERT_EQ(test, err, 0 );
/* Assert */
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data,
checksum.data, checksum.len), 0 ,
"checksum mismatch" );
crypto_free_ahash(tfm);
}
#define DEFINE_HEX_XDR_NETOBJ(name, hex_array...) \
static const u8 name ## _data[] = { hex_array }; \
static const struct xdr_netobj name = { \
.data = (u8 *)name## _data, \
.len = sizeof (name## _data), \
}
#define DEFINE_STR_XDR_NETOBJ(name, string) \
static const u8 name ## _str[] = string; \
static const struct xdr_netobj name = { \
.data = (u8 *)name## _str, \
.len = sizeof (name## _str) - 1 , \
}
/*
* RFC 3961 Appendix A.1. n-fold
*
* The n-fold function is defined in section 5.1 of RFC 3961.
*
* This test material is copyright (C) The Internet Society (2005).
*/
DEFINE_HEX_XDR_NETOBJ(nfold_test1_plaintext,
0 x30, 0 x31, 0 x32, 0 x33, 0 x34, 0 x35
);
DEFINE_HEX_XDR_NETOBJ(nfold_test1_expected_result,
0 xbe, 0 x07, 0 x26, 0 x31, 0 x27, 0 x6b, 0 x19, 0 x55
);
DEFINE_HEX_XDR_NETOBJ(nfold_test2_plaintext,
0 x70, 0 x61, 0 x73, 0 x73, 0 x77, 0 x6f, 0 x72, 0 x64
);
DEFINE_HEX_XDR_NETOBJ(nfold_test2_expected_result,
0 x78, 0 xa0, 0 x7b, 0 x6c, 0 xaf, 0 x85, 0 xfa
);
DEFINE_HEX_XDR_NETOBJ(nfold_test3_plaintext,
0 x52, 0 x6f, 0 x75, 0 x67, 0 x68, 0 x20, 0 x43, 0 x6f,
0 x6e, 0 x73, 0 x65, 0 x6e, 0 x73, 0 x75, 0 x73, 0 x2c,
0 x20, 0 x61, 0 x6e, 0 x64, 0 x20, 0 x52, 0 x75, 0 x6e,
0 x6e, 0 x69, 0 x6e, 0 x67, 0 x20, 0 x43, 0 x6f, 0 x64,
0 x65
);
DEFINE_HEX_XDR_NETOBJ(nfold_test3_expected_result,
0 xbb, 0 x6e, 0 xd3, 0 x08, 0 x70, 0 xb7, 0 xf0, 0 xe0
);
DEFINE_HEX_XDR_NETOBJ(nfold_test4_plaintext,
0 x70, 0 x61, 0 x73, 0 x73, 0 x77, 0 x6f, 0 x72, 0 x64
);
DEFINE_HEX_XDR_NETOBJ(nfold_test4_expected_result,
0 x59, 0 xe4, 0 xa8, 0 xca, 0 x7c, 0 x03, 0 x85, 0 xc3,
0 xc3, 0 x7b, 0 x3f, 0 x6d, 0 x20, 0 x00, 0 x24, 0 x7c,
0 xb6, 0 xe6, 0 xbd, 0 x5b, 0 x3e
);
DEFINE_HEX_XDR_NETOBJ(nfold_test5_plaintext,
0 x4d, 0 x41, 0 x53, 0 x53, 0 x41, 0 x43, 0 x48, 0 x56,
0 x53, 0 x45, 0 x54, 0 x54, 0 x53, 0 x20, 0 x49, 0 x4e,
0 x53, 0 x54, 0 x49, 0 x54, 0 x56, 0 x54, 0 x45, 0 x20,
0 x4f, 0 x46, 0 x20, 0 x54, 0 x45, 0 x43, 0 x48, 0 x4e,
0 x4f, 0 x4c, 0 x4f, 0 x47, 0 x59
);
DEFINE_HEX_XDR_NETOBJ(nfold_test5_expected_result,
0 xdb, 0 x3b, 0 x0d, 0 x8f, 0 x0b, 0 x06, 0 x1e, 0 x60,
0 x32, 0 x82, 0 xb3, 0 x08, 0 xa5, 0 x08, 0 x41, 0 x22,
0 x9a, 0 xd7, 0 x98, 0 xfa, 0 xb9, 0 x54, 0 x0c, 0 x1b
);
DEFINE_HEX_XDR_NETOBJ(nfold_test6_plaintext,
0 x51
);
DEFINE_HEX_XDR_NETOBJ(nfold_test6_expected_result,
0 x51, 0 x8a, 0 x54, 0 xa2, 0 x15, 0 xa8, 0 x45, 0 x2a,
0 x51, 0 x8a, 0 x54, 0 xa2, 0 x15, 0 xa8, 0 x45, 0 x2a,
0 x51, 0 x8a, 0 x54, 0 xa2, 0 x15
);
DEFINE_HEX_XDR_NETOBJ(nfold_test7_plaintext,
0 x62, 0 x61
);
DEFINE_HEX_XDR_NETOBJ(nfold_test7_expected_result,
0 xfb, 0 x25, 0 xd5, 0 x31, 0 xae, 0 x89, 0 x74, 0 x49,
0 x9f, 0 x52, 0 xfd, 0 x92, 0 xea, 0 x98, 0 x57, 0 xc4,
0 xba, 0 x24, 0 xcf, 0 x29, 0 x7e
);
DEFINE_HEX_XDR_NETOBJ(nfold_test_kerberos,
0 x6b, 0 x65, 0 x72, 0 x62, 0 x65, 0 x72, 0 x6f, 0 x73
);
DEFINE_HEX_XDR_NETOBJ(nfold_test8_expected_result,
0 x6b, 0 x65, 0 x72, 0 x62, 0 x65, 0 x72, 0 x6f, 0 x73
);
DEFINE_HEX_XDR_NETOBJ(nfold_test9_expected_result,
0 x6b, 0 x65, 0 x72, 0 x62, 0 x65, 0 x72, 0 x6f, 0 x73,
0 x7b, 0 x9b, 0 x5b, 0 x2b, 0 x93, 0 x13, 0 x2b, 0 x93
);
DEFINE_HEX_XDR_NETOBJ(nfold_test10_expected_result,
0 x83, 0 x72, 0 xc2, 0 x36, 0 x34, 0 x4e, 0 x5f, 0 x15,
0 x50, 0 xcd, 0 x07, 0 x47, 0 xe1, 0 x5d, 0 x62, 0 xca,
0 x7a, 0 x5a, 0 x3b, 0 xce, 0 xa4
);
DEFINE_HEX_XDR_NETOBJ(nfold_test11_expected_result,
0 x6b, 0 x65, 0 x72, 0 x62, 0 x65, 0 x72, 0 x6f, 0 x73,
0 x7b, 0 x9b, 0 x5b, 0 x2b, 0 x93, 0 x13, 0 x2b, 0 x93,
0 x5c, 0 x9b, 0 xdc, 0 xda, 0 xd9, 0 x5c, 0 x98, 0 x99,
0 xc4, 0 xca, 0 xe4, 0 xde, 0 xe6, 0 xd6, 0 xca, 0 xe4
);
static const struct gss_krb5_test_param rfc3961_nfold_test_params[] = {
{
.desc = "64-fold(\" 012345 \")" ,
.nfold = 64 ,
.plaintext = &nfold_test1_plaintext,
.expected_result = &nfold_test1_expected_result,
},
{
.desc = "56-fold(\" password\")" ,
.nfold = 56 ,
.plaintext = &nfold_test2_plaintext,
.expected_result = &nfold_test2_expected_result,
},
{
.desc = "64-fold(\" Rough Consensus, and Running Code\")" ,
.nfold = 64 ,
.plaintext = &nfold_test3_plaintext,
.expected_result = &nfold_test3_expected_result,
},
{
.desc = "168-fold(\" password\")" ,
.nfold = 168 ,
.plaintext = &nfold_test4_plaintext,
.expected_result = &nfold_test4_expected_result,
},
{
.desc = "192-fold(\" MASSACHVSETTS INSTITVTE OF TECHNOLOGY\")" ,
.nfold = 192 ,
.plaintext = &nfold_test5_plaintext,
.expected_result = &nfold_test5_expected_result,
},
{
.desc = "168-fold(\" Q\")" ,
.nfold = 168 ,
.plaintext = &nfold_test6_plaintext,
.expected_result = &nfold_test6_expected_result,
},
{
.desc = "168-fold(\" ba\")" ,
.nfold = 168 ,
.plaintext = &nfold_test7_plaintext,
.expected_result = &nfold_test7_expected_result,
},
{
.desc = "64-fold(\" kerberos\")" ,
.nfold = 64 ,
.plaintext = &nfold_test_kerberos,
.expected_result = &nfold_test8_expected_result,
},
{
.desc = "128-fold(\" kerberos\")" ,
.nfold = 128 ,
.plaintext = &nfold_test_kerberos,
.expected_result = &nfold_test9_expected_result,
},
{
.desc = "168-fold(\" kerberos\")" ,
.nfold = 168 ,
.plaintext = &nfold_test_kerberos,
.expected_result = &nfold_test10_expected_result,
},
{
.desc = "256-fold(\" kerberos\")" ,
.nfold = 256 ,
.plaintext = &nfold_test_kerberos,
.expected_result = &nfold_test11_expected_result,
},
};
/* Creates the function rfc3961_nfold_gen_params */
KUNIT_ARRAY_PARAM(rfc3961_nfold, rfc3961_nfold_test_params, gss_krb5_get_desc);
static void rfc3961_nfold_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
u8 *result;
/* Arrange */
result = kunit_kzalloc(test, 4096 , GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, result);
/* Act */
krb5_nfold(param->plaintext->len * 8 , param->plaintext->data,
param->expected_result->len * 8 , result);
/* Assert */
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data,
result, param->expected_result->len), 0 ,
"result mismatch" );
}
static struct kunit_case rfc3961_test_cases[] = {
{
.name = "RFC 3961 n-fold" ,
.run_case = rfc3961_nfold_case,
.generate_params = rfc3961_nfold_gen_params,
},
{}
};
static struct kunit_suite rfc3961_suite = {
.name = "RFC 3961 tests" ,
.test_cases = rfc3961_test_cases,
};
/*
* From RFC 3962 Appendix B: Sample Test Vectors
*
* Some test vectors for CBC with ciphertext stealing, using an
* initial vector of all-zero.
*
* This test material is copyright (C) The Internet Society (2005).
*/
DEFINE_HEX_XDR_NETOBJ(rfc3962_encryption_key,
0 x63, 0 x68, 0 x69, 0 x63, 0 x6b, 0 x65, 0 x6e, 0 x20,
0 x74, 0 x65, 0 x72, 0 x69, 0 x79, 0 x61, 0 x6b, 0 x69
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test1_plaintext,
0 x49, 0 x20, 0 x77, 0 x6f, 0 x75, 0 x6c, 0 x64, 0 x20,
0 x6c, 0 x69, 0 x6b, 0 x65, 0 x20, 0 x74, 0 x68, 0 x65,
0 x20
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test1_expected_result,
0 xc6, 0 x35, 0 x35, 0 x68, 0 xf2, 0 xbf, 0 x8c, 0 xb4,
0 xd8, 0 xa5, 0 x80, 0 x36, 0 x2d, 0 xa7, 0 xff, 0 x7f,
0 x97
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test1_next_iv,
0 xc6, 0 x35, 0 x35, 0 x68, 0 xf2, 0 xbf, 0 x8c, 0 xb4,
0 xd8, 0 xa5, 0 x80, 0 x36, 0 x2d, 0 xa7, 0 xff, 0 x7f
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test2_plaintext,
0 x49, 0 x20, 0 x77, 0 x6f, 0 x75, 0 x6c, 0 x64, 0 x20,
0 x6c, 0 x69, 0 x6b, 0 x65, 0 x20, 0 x74, 0 x68, 0 x65,
0 x20, 0 x47, 0 x65, 0 x6e, 0 x65, 0 x72, 0 x61, 0 x6c,
0 x20, 0 x47, 0 x61, 0 x75, 0 x27, 0 x73, 0 x20
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test2_expected_result,
0 xfc, 0 x00, 0 x78, 0 x3e, 0 x0e, 0 xfd, 0 xb2, 0 xc1,
0 xd4, 0 x45, 0 xd4, 0 xc8, 0 xef, 0 xf7, 0 xed, 0 x22,
0 x97, 0 x68, 0 x72, 0 x68, 0 xd6, 0 xec, 0 xcc, 0 xc0,
0 xc0, 0 x7b, 0 x25, 0 xe2, 0 x5e, 0 xcf, 0 xe5
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test2_next_iv,
0 xfc, 0 x00, 0 x78, 0 x3e, 0 x0e, 0 xfd, 0 xb2, 0 xc1,
0 xd4, 0 x45, 0 xd4, 0 xc8, 0 xef, 0 xf7, 0 xed, 0 x22
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test3_plaintext,
0 x49, 0 x20, 0 x77, 0 x6f, 0 x75, 0 x6c, 0 x64, 0 x20,
0 x6c, 0 x69, 0 x6b, 0 x65, 0 x20, 0 x74, 0 x68, 0 x65,
0 x20, 0 x47, 0 x65, 0 x6e, 0 x65, 0 x72, 0 x61, 0 x6c,
0 x20, 0 x47, 0 x61, 0 x75, 0 x27, 0 x73, 0 x20, 0 x43
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test3_expected_result,
0 x39, 0 x31, 0 x25, 0 x23, 0 xa7, 0 x86, 0 x62, 0 xd5,
0 xbe, 0 x7f, 0 xcb, 0 xcc, 0 x98, 0 xeb, 0 xf5, 0 xa8,
0 x97, 0 x68, 0 x72, 0 x68, 0 xd6, 0 xec, 0 xcc, 0 xc0,
0 xc0, 0 x7b, 0 x25, 0 xe2, 0 x5e, 0 xcf, 0 xe5, 0 x84
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test3_next_iv,
0 x39, 0 x31, 0 x25, 0 x23, 0 xa7, 0 x86, 0 x62, 0 xd5,
0 xbe, 0 x7f, 0 xcb, 0 xcc, 0 x98, 0 xeb, 0 xf5, 0 xa8
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test4_plaintext,
0 x49, 0 x20, 0 x77, 0 x6f, 0 x75, 0 x6c, 0 x64, 0 x20,
0 x6c, 0 x69, 0 x6b, 0 x65, 0 x20, 0 x74, 0 x68, 0 x65,
0 x20, 0 x47, 0 x65, 0 x6e, 0 x65, 0 x72, 0 x61, 0 x6c,
0 x20, 0 x47, 0 x61, 0 x75, 0 x27, 0 x73, 0 x20, 0 x43,
0 x68, 0 x69, 0 x63, 0 x6b, 0 x65, 0 x6e, 0 x2c, 0 x20,
0 x70, 0 x6c, 0 x65, 0 x61, 0 x73, 0 x65, 0 x2c
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test4_expected_result,
0 x97, 0 x68, 0 x72, 0 x68, 0 xd6, 0 xec, 0 xcc, 0 xc0,
0 xc0, 0 x7b, 0 x25, 0 xe2, 0 x5e, 0 xcf, 0 xe5, 0 x84,
0 xb3, 0 xff, 0 xfd, 0 x94, 0 x0c, 0 x16, 0 xa1, 0 x8c,
0 x1b, 0 x55, 0 x49, 0 xd2, 0 xf8, 0 x38, 0 x02, 0 x9e,
0 x39, 0 x31, 0 x25, 0 x23, 0 xa7, 0 x86, 0 x62, 0 xd5,
0 xbe, 0 x7f, 0 xcb, 0 xcc, 0 x98, 0 xeb, 0 xf5
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test4_next_iv,
0 xb3, 0 xff, 0 xfd, 0 x94, 0 x0c, 0 x16, 0 xa1, 0 x8c,
0 x1b, 0 x55, 0 x49, 0 xd2, 0 xf8, 0 x38, 0 x02, 0 x9e
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test5_plaintext,
0 x49, 0 x20, 0 x77, 0 x6f, 0 x75, 0 x6c, 0 x64, 0 x20,
0 x6c, 0 x69, 0 x6b, 0 x65, 0 x20, 0 x74, 0 x68, 0 x65,
0 x20, 0 x47, 0 x65, 0 x6e, 0 x65, 0 x72, 0 x61, 0 x6c,
0 x20, 0 x47, 0 x61, 0 x75, 0 x27, 0 x73, 0 x20, 0 x43,
0 x68, 0 x69, 0 x63, 0 x6b, 0 x65, 0 x6e, 0 x2c, 0 x20,
0 x70, 0 x6c, 0 x65, 0 x61, 0 x73, 0 x65, 0 x2c, 0 x20
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test5_expected_result,
0 x97, 0 x68, 0 x72, 0 x68, 0 xd6, 0 xec, 0 xcc, 0 xc0,
0 xc0, 0 x7b, 0 x25, 0 xe2, 0 x5e, 0 xcf, 0 xe5, 0 x84,
0 x9d, 0 xad, 0 x8b, 0 xbb, 0 x96, 0 xc4, 0 xcd, 0 xc0,
0 x3b, 0 xc1, 0 x03, 0 xe1, 0 xa1, 0 x94, 0 xbb, 0 xd8,
0 x39, 0 x31, 0 x25, 0 x23, 0 xa7, 0 x86, 0 x62, 0 xd5,
0 xbe, 0 x7f, 0 xcb, 0 xcc, 0 x98, 0 xeb, 0 xf5, 0 xa8
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test5_next_iv,
0 x9d, 0 xad, 0 x8b, 0 xbb, 0 x96, 0 xc4, 0 xcd, 0 xc0,
0 x3b, 0 xc1, 0 x03, 0 xe1, 0 xa1, 0 x94, 0 xbb, 0 xd8
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test6_plaintext,
0 x49, 0 x20, 0 x77, 0 x6f, 0 x75, 0 x6c, 0 x64, 0 x20,
0 x6c, 0 x69, 0 x6b, 0 x65, 0 x20, 0 x74, 0 x68, 0 x65,
0 x20, 0 x47, 0 x65, 0 x6e, 0 x65, 0 x72, 0 x61, 0 x6c,
0 x20, 0 x47, 0 x61, 0 x75, 0 x27, 0 x73, 0 x20, 0 x43,
0 x68, 0 x69, 0 x63, 0 x6b, 0 x65, 0 x6e, 0 x2c, 0 x20,
0 x70, 0 x6c, 0 x65, 0 x61, 0 x73, 0 x65, 0 x2c, 0 x20,
0 x61, 0 x6e, 0 x64, 0 x20, 0 x77, 0 x6f, 0 x6e, 0 x74,
0 x6f, 0 x6e, 0 x20, 0 x73, 0 x6f, 0 x75, 0 x70, 0 x2e
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test6_expected_result,
0 x97, 0 x68, 0 x72, 0 x68, 0 xd6, 0 xec, 0 xcc, 0 xc0,
0 xc0, 0 x7b, 0 x25, 0 xe2, 0 x5e, 0 xcf, 0 xe5, 0 x84,
0 x39, 0 x31, 0 x25, 0 x23, 0 xa7, 0 x86, 0 x62, 0 xd5,
0 xbe, 0 x7f, 0 xcb, 0 xcc, 0 x98, 0 xeb, 0 xf5, 0 xa8,
0 x48, 0 x07, 0 xef, 0 xe8, 0 x36, 0 xee, 0 x89, 0 xa5,
0 x26, 0 x73, 0 x0d, 0 xbc, 0 x2f, 0 x7b, 0 xc8, 0 x40,
0 x9d, 0 xad, 0 x8b, 0 xbb, 0 x96, 0 xc4, 0 xcd, 0 xc0,
0 x3b, 0 xc1, 0 x03, 0 xe1, 0 xa1, 0 x94, 0 xbb, 0 xd8
);
DEFINE_HEX_XDR_NETOBJ(rfc3962_enc_test6_next_iv,
0 x48, 0 x07, 0 xef, 0 xe8, 0 x36, 0 xee, 0 x89, 0 xa5,
0 x26, 0 x73, 0 x0d, 0 xbc, 0 x2f, 0 x7b, 0 xc8, 0 x40
);
static const struct gss_krb5_test_param rfc3962_encrypt_test_params[] = {
{
.desc = "Encrypt with aes128-cts-hmac-sha1-96 case 1" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &rfc3962_enc_test1_plaintext,
.expected_result = &rfc3962_enc_test1_expected_result,
.next_iv = &rfc3962_enc_test1_next_iv,
},
{
.desc = "Encrypt with aes128-cts-hmac-sha1-96 case 2" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &rfc3962_enc_test2_plaintext,
.expected_result = &rfc3962_enc_test2_expected_result,
.next_iv = &rfc3962_enc_test2_next_iv,
},
{
.desc = "Encrypt with aes128-cts-hmac-sha1-96 case 3" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &rfc3962_enc_test3_plaintext,
.expected_result = &rfc3962_enc_test3_expected_result,
.next_iv = &rfc3962_enc_test3_next_iv,
},
{
.desc = "Encrypt with aes128-cts-hmac-sha1-96 case 4" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &rfc3962_enc_test4_plaintext,
.expected_result = &rfc3962_enc_test4_expected_result,
.next_iv = &rfc3962_enc_test4_next_iv,
},
{
.desc = "Encrypt with aes128-cts-hmac-sha1-96 case 5" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &rfc3962_enc_test5_plaintext,
.expected_result = &rfc3962_enc_test5_expected_result,
.next_iv = &rfc3962_enc_test5_next_iv,
},
{
.desc = "Encrypt with aes128-cts-hmac-sha1-96 case 6" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &rfc3962_enc_test6_plaintext,
.expected_result = &rfc3962_enc_test6_expected_result,
.next_iv = &rfc3962_enc_test6_next_iv,
},
};
/* Creates the function rfc3962_encrypt_gen_params */
KUNIT_ARRAY_PARAM(rfc3962_encrypt, rfc3962_encrypt_test_params,
gss_krb5_get_desc);
/*
* This tests the implementation of the encryption part of the mechanism.
* It does not apply a confounder or test the result of HMAC over the
* plaintext.
*/
static void rfc3962_encrypt_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
const struct gss_krb5_enctype *gk5e;
struct xdr_buf buf;
void *iv, *text;
u32 err;
/* Arrange */
gk5e = gss_krb5_lookup_enctype(param->enctype);
if (!gk5e)
kunit_skip(test, "Encryption type is not available" );
cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
err = crypto_sync_skcipher_setkey(cbc_tfm, param->Ke->data, param->Ke->len);
KUNIT_ASSERT_EQ(test, err, 0 );
cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
err = crypto_sync_skcipher_setkey(cts_tfm, param->Ke->data, param->Ke->len);
KUNIT_ASSERT_EQ(test, err, 0 );
iv = kunit_kzalloc(test, crypto_sync_skcipher_ivsize(cts_tfm), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, iv);
text = kunit_kzalloc(test, param->plaintext->len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
memcpy(text, param->plaintext->data, param->plaintext->len);
memset(&buf, 0 , sizeof (buf));
buf.head[0 ].iov_base = text;
buf.head[0 ].iov_len = param->plaintext->len;
buf.len = buf.head[0 ].iov_len;
/* Act */
err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0 , &buf, NULL,
iv, crypto_sync_skcipher_ivsize(cts_tfm));
KUNIT_ASSERT_EQ(test, err, 0 );
/* Assert */
KUNIT_EXPECT_EQ_MSG(test,
param->expected_result->len, buf.len,
"ciphertext length mismatch" );
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data,
text, param->expected_result->len), 0 ,
"ciphertext mismatch" );
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->next_iv->data, iv,
param->next_iv->len), 0 ,
"IV mismatch" );
crypto_free_sync_skcipher(cts_tfm);
crypto_free_sync_skcipher(cbc_tfm);
}
static struct kunit_case rfc3962_test_cases[] = {
{
.name = "RFC 3962 encryption" ,
.run_case = rfc3962_encrypt_case,
.generate_params = rfc3962_encrypt_gen_params,
},
{}
};
static struct kunit_suite rfc3962_suite = {
.name = "RFC 3962 suite" ,
.test_cases = rfc3962_test_cases,
};
/*
* From RFC 6803 Section 10. Test vectors
*
* Sample results for key derivation
*
* Copyright (c) 2012 IETF Trust and the persons identified as the
* document authors. All rights reserved.
*/
DEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_basekey,
0 x57, 0 xd0, 0 x29, 0 x72, 0 x98, 0 xff, 0 xd9, 0 xd3,
0 x5d, 0 xe5, 0 xa4, 0 x7f, 0 xb4, 0 xbd, 0 xe2, 0 x4b
);
DEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_Kc,
0 xd1, 0 x55, 0 x77, 0 x5a, 0 x20, 0 x9d, 0 x05, 0 xf0,
0 x2b, 0 x38, 0 xd4, 0 x2a, 0 x38, 0 x9e, 0 x5a, 0 x56
);
DEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_Ke,
0 x64, 0 xdf, 0 x83, 0 xf8, 0 x5a, 0 x53, 0 x2f, 0 x17,
0 x57, 0 x7d, 0 x8c, 0 x37, 0 x03, 0 x57, 0 x96, 0 xab
);
DEFINE_HEX_XDR_NETOBJ(camellia128_cts_cmac_Ki,
0 x3e, 0 x4f, 0 xbd, 0 xf3, 0 x0f, 0 xb8, 0 x25, 0 x9c,
0 x42, 0 x5c, 0 xb6, 0 xc9, 0 x6f, 0 x1f, 0 x46, 0 x35
);
DEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_basekey,
0 xb9, 0 xd6, 0 x82, 0 x8b, 0 x20, 0 x56, 0 xb7, 0 xbe,
0 x65, 0 x6d, 0 x88, 0 xa1, 0 x23, 0 xb1, 0 xfa, 0 xc6,
0 x82, 0 x14, 0 xac, 0 x2b, 0 x72, 0 x7e, 0 xcf, 0 x5f,
0 x69, 0 xaf, 0 xe0, 0 xc4, 0 xdf, 0 x2a, 0 x6d, 0 x2c
);
DEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_Kc,
0 xe4, 0 x67, 0 xf9, 0 xa9, 0 x55, 0 x2b, 0 xc7, 0 xd3,
0 x15, 0 x5a, 0 x62, 0 x20, 0 xaf, 0 x9c, 0 x19, 0 x22,
0 x0e, 0 xee, 0 xd4, 0 xff, 0 x78, 0 xb0, 0 xd1, 0 xe6,
0 xa1, 0 x54, 0 x49, 0 x91, 0 x46, 0 x1a, 0 x9e, 0 x50
);
DEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_Ke,
0 x41, 0 x2a, 0 xef, 0 xc3, 0 x62, 0 xa7, 0 x28, 0 x5f,
0 xc3, 0 x96, 0 x6c, 0 x6a, 0 x51, 0 x81, 0 xe7, 0 x60,
0 x5a, 0 xe6, 0 x75, 0 x23, 0 x5b, 0 x6d, 0 x54, 0 x9f,
0 xbf, 0 xc9, 0 xab, 0 x66, 0 x30, 0 xa4, 0 xc6, 0 x04
);
DEFINE_HEX_XDR_NETOBJ(camellia256_cts_cmac_Ki,
0 xfa, 0 x62, 0 x4f, 0 xa0, 0 xe5, 0 x23, 0 x99, 0 x3f,
0 xa3, 0 x88, 0 xae, 0 xfd, 0 xc6, 0 x7e, 0 x67, 0 xeb,
0 xcd, 0 x8c, 0 x08, 0 xe8, 0 xa0, 0 x24, 0 x6b, 0 x1d,
0 x73, 0 xb0, 0 xd1, 0 xdd, 0 x9f, 0 xc5, 0 x82, 0 xb0
);
DEFINE_HEX_XDR_NETOBJ(usage_checksum,
0 x00, 0 x00, 0 x00, 0 x02, KEY_USAGE_SEED_CHECKSUM
);
DEFINE_HEX_XDR_NETOBJ(usage_encryption,
0 x00, 0 x00, 0 x00, 0 x02, KEY_USAGE_SEED_ENCRYPTION
);
DEFINE_HEX_XDR_NETOBJ(usage_integrity,
0 x00, 0 x00, 0 x00, 0 x02, KEY_USAGE_SEED_INTEGRITY
);
static const struct gss_krb5_test_param rfc6803_kdf_test_params[] = {
{
.desc = "Derive Kc subkey for camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.base_key = &camellia128_cts_cmac_basekey,
.usage = &usage_checksum,
.expected_result = &camellia128_cts_cmac_Kc,
},
{
.desc = "Derive Ke subkey for camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.base_key = &camellia128_cts_cmac_basekey,
.usage = &usage_encryption,
.expected_result = &camellia128_cts_cmac_Ke,
},
{
.desc = "Derive Ki subkey for camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.base_key = &camellia128_cts_cmac_basekey,
.usage = &usage_integrity,
.expected_result = &camellia128_cts_cmac_Ki,
},
{
.desc = "Derive Kc subkey for camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.base_key = &camellia256_cts_cmac_basekey,
.usage = &usage_checksum,
.expected_result = &camellia256_cts_cmac_Kc,
},
{
.desc = "Derive Ke subkey for camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.base_key = &camellia256_cts_cmac_basekey,
.usage = &usage_encryption,
.expected_result = &camellia256_cts_cmac_Ke,
},
{
.desc = "Derive Ki subkey for camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.base_key = &camellia256_cts_cmac_basekey,
.usage = &usage_integrity,
.expected_result = &camellia256_cts_cmac_Ki,
},
};
/* Creates the function rfc6803_kdf_gen_params */
KUNIT_ARRAY_PARAM(rfc6803_kdf, rfc6803_kdf_test_params, gss_krb5_get_desc);
/*
* From RFC 6803 Section 10. Test vectors
*
* Sample checksums.
*
* Copyright (c) 2012 IETF Trust and the persons identified as the
* document authors. All rights reserved.
*
* XXX: These tests are likely to fail on EBCDIC or Unicode platforms.
*/
DEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test1_plaintext,
"abcdefghijk" );
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test1_basekey,
0 x1d, 0 xc4, 0 x6a, 0 x8d, 0 x76, 0 x3f, 0 x4f, 0 x93,
0 x74, 0 x2b, 0 xcb, 0 xa3, 0 x38, 0 x75, 0 x76, 0 xc3
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test1_usage,
0 x00, 0 x00, 0 x00, 0 x07, KEY_USAGE_SEED_CHECKSUM
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test1_expected_result,
0 x11, 0 x78, 0 xe6, 0 xc5, 0 xc4, 0 x7a, 0 x8c, 0 x1a,
0 xe0, 0 xc4, 0 xb9, 0 xc7, 0 xd4, 0 xeb, 0 x7b, 0 x6b
);
DEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test2_plaintext,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test2_basekey,
0 x50, 0 x27, 0 xbc, 0 x23, 0 x1d, 0 x0f, 0 x3a, 0 x9d,
0 x23, 0 x33, 0 x3f, 0 x1c, 0 xa6, 0 xfd, 0 xbe, 0 x7c
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test2_usage,
0 x00, 0 x00, 0 x00, 0 x08, KEY_USAGE_SEED_CHECKSUM
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test2_expected_result,
0 xd1, 0 xb3, 0 x4f, 0 x70, 0 x04, 0 xa7, 0 x31, 0 xf2,
0 x3a, 0 x0c, 0 x00, 0 xbf, 0 x6c, 0 x3f, 0 x75, 0 x3a
);
DEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test3_plaintext,
"123456789" );
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test3_basekey,
0 xb6, 0 x1c, 0 x86, 0 xcc, 0 x4e, 0 x5d, 0 x27, 0 x57,
0 x54, 0 x5a, 0 xd4, 0 x23, 0 x39, 0 x9f, 0 xb7, 0 x03,
0 x1e, 0 xca, 0 xb9, 0 x13, 0 xcb, 0 xb9, 0 x00, 0 xbd,
0 x7a, 0 x3c, 0 x6d, 0 xd8, 0 xbf, 0 x92, 0 x01, 0 x5b
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test3_usage,
0 x00, 0 x00, 0 x00, 0 x09, KEY_USAGE_SEED_CHECKSUM
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test3_expected_result,
0 x87, 0 xa1, 0 x2c, 0 xfd, 0 x2b, 0 x96, 0 x21, 0 x48,
0 x10, 0 xf0, 0 x1c, 0 x82, 0 x6e, 0 x77, 0 x44, 0 xb1
);
DEFINE_STR_XDR_NETOBJ(rfc6803_checksum_test4_plaintext,
"!@#$%^&*()!@#$%^&*()!@#$%^&*()" );
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test4_basekey,
0 x32, 0 x16, 0 x4c, 0 x5b, 0 x43, 0 x4d, 0 x1d, 0 x15,
0 x38, 0 xe4, 0 xcf, 0 xd9, 0 xbe, 0 x80, 0 x40, 0 xfe,
0 x8c, 0 x4a, 0 xc7, 0 xac, 0 xc4, 0 xb9, 0 x3d, 0 x33,
0 x14, 0 xd2, 0 x13, 0 x36, 0 x68, 0 x14, 0 x7a, 0 x05
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test4_usage,
0 x00, 0 x00, 0 x00, 0 x0a, KEY_USAGE_SEED_CHECKSUM
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_checksum_test4_expected_result,
0 x3f, 0 xa0, 0 xb4, 0 x23, 0 x55, 0 xe5, 0 x2b, 0 x18,
0 x91, 0 x87, 0 x29, 0 x4a, 0 xa2, 0 x52, 0 xab, 0 x64
);
static const struct gss_krb5_test_param rfc6803_checksum_test_params[] = {
{
.desc = "camellia128-cts-cmac checksum test 1" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.base_key = &rfc6803_checksum_test1_basekey,
.usage = &rfc6803_checksum_test1_usage,
.plaintext = &rfc6803_checksum_test1_plaintext,
.expected_result = &rfc6803_checksum_test1_expected_result,
},
{
.desc = "camellia128-cts-cmac checksum test 2" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.base_key = &rfc6803_checksum_test2_basekey,
.usage = &rfc6803_checksum_test2_usage,
.plaintext = &rfc6803_checksum_test2_plaintext,
.expected_result = &rfc6803_checksum_test2_expected_result,
},
{
.desc = "camellia256-cts-cmac checksum test 3" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.base_key = &rfc6803_checksum_test3_basekey,
.usage = &rfc6803_checksum_test3_usage,
.plaintext = &rfc6803_checksum_test3_plaintext,
.expected_result = &rfc6803_checksum_test3_expected_result,
},
{
.desc = "camellia256-cts-cmac checksum test 4" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.base_key = &rfc6803_checksum_test4_basekey,
.usage = &rfc6803_checksum_test4_usage,
.plaintext = &rfc6803_checksum_test4_plaintext,
.expected_result = &rfc6803_checksum_test4_expected_result,
},
};
/* Creates the function rfc6803_checksum_gen_params */
KUNIT_ARRAY_PARAM(rfc6803_checksum, rfc6803_checksum_test_params,
gss_krb5_get_desc);
/*
* From RFC 6803 Section 10. Test vectors
*
* Sample encryptions (all using the default cipher state)
*
* Copyright (c) 2012 IETF Trust and the persons identified as the
* document authors. All rights reserved.
*
* Key usage values are from errata 4326 against RFC 6803.
*/
static const struct xdr_netobj rfc6803_enc_empty_plaintext = {
.len = 0 ,
};
DEFINE_STR_XDR_NETOBJ(rfc6803_enc_1byte_plaintext, "1" );
DEFINE_STR_XDR_NETOBJ(rfc6803_enc_9byte_plaintext, "9 bytesss" );
DEFINE_STR_XDR_NETOBJ(rfc6803_enc_13byte_plaintext, "13 bytes byte" );
DEFINE_STR_XDR_NETOBJ(rfc6803_enc_30byte_plaintext,
"30 bytes bytes bytes bytes byt"
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test1_confounder,
0 xb6, 0 x98, 0 x22, 0 xa1, 0 x9a, 0 x6b, 0 x09, 0 xc0,
0 xeb, 0 xc8, 0 x55, 0 x7d, 0 x1f, 0 x1b, 0 x6c, 0 x0a
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test1_basekey,
0 x1d, 0 xc4, 0 x6a, 0 x8d, 0 x76, 0 x3f, 0 x4f, 0 x93,
0 x74, 0 x2b, 0 xcb, 0 xa3, 0 x38, 0 x75, 0 x76, 0 xc3
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test1_expected_result,
0 xc4, 0 x66, 0 xf1, 0 x87, 0 x10, 0 x69, 0 x92, 0 x1e,
0 xdb, 0 x7c, 0 x6f, 0 xde, 0 x24, 0 x4a, 0 x52, 0 xdb,
0 x0b, 0 xa1, 0 x0e, 0 xdc, 0 x19, 0 x7b, 0 xdb, 0 x80,
0 x06, 0 x65, 0 x8c, 0 xa3, 0 xcc, 0 xce, 0 x6e, 0 xb8
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test2_confounder,
0 x6f, 0 x2f, 0 xc3, 0 xc2, 0 xa1, 0 x66, 0 xfd, 0 x88,
0 x98, 0 x96, 0 x7a, 0 x83, 0 xde, 0 x95, 0 x96, 0 xd9
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test2_basekey,
0 x50, 0 x27, 0 xbc, 0 x23, 0 x1d, 0 x0f, 0 x3a, 0 x9d,
0 x23, 0 x33, 0 x3f, 0 x1c, 0 xa6, 0 xfd, 0 xbe, 0 x7c
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test2_expected_result,
0 x84, 0 x2d, 0 x21, 0 xfd, 0 x95, 0 x03, 0 x11, 0 xc0,
0 xdd, 0 x46, 0 x4a, 0 x3f, 0 x4b, 0 xe8, 0 xd6, 0 xda,
0 x88, 0 xa5, 0 x6d, 0 x55, 0 x9c, 0 x9b, 0 x47, 0 xd3,
0 xf9, 0 xa8, 0 x50, 0 x67, 0 xaf, 0 x66, 0 x15, 0 x59,
0 xb8
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test3_confounder,
0 xa5, 0 xb4, 0 xa7, 0 x1e, 0 x07, 0 x7a, 0 xee, 0 xf9,
0 x3c, 0 x87, 0 x63, 0 xc1, 0 x8f, 0 xdb, 0 x1f, 0 x10
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test3_basekey,
0 xa1, 0 xbb, 0 x61, 0 xe8, 0 x05, 0 xf9, 0 xba, 0 x6d,
0 xde, 0 x8f, 0 xdb, 0 xdd, 0 xc0, 0 x5c, 0 xde, 0 xa0
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test3_expected_result,
0 x61, 0 x9f, 0 xf0, 0 x72, 0 xe3, 0 x62, 0 x86, 0 xff,
0 x0a, 0 x28, 0 xde, 0 xb3, 0 xa3, 0 x52, 0 xec, 0 x0d,
0 x0e, 0 xdf, 0 x5c, 0 x51, 0 x60, 0 xd6, 0 x63, 0 xc9,
0 x01, 0 x75, 0 x8c, 0 xcf, 0 x9d, 0 x1e, 0 xd3, 0 x3d,
0 x71, 0 xdb, 0 x8f, 0 x23, 0 xaa, 0 xbf, 0 x83, 0 x48,
0 xa0
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test4_confounder,
0 x19, 0 xfe, 0 xe4, 0 x0d, 0 x81, 0 x0c, 0 x52, 0 x4b,
0 x5b, 0 x22, 0 xf0, 0 x18, 0 x74, 0 xc6, 0 x93, 0 xda
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test4_basekey,
0 x2c, 0 xa2, 0 x7a, 0 x5f, 0 xaf, 0 x55, 0 x32, 0 x24,
0 x45, 0 x06, 0 x43, 0 x4e, 0 x1c, 0 xef, 0 x66, 0 x76
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test4_expected_result,
0 xb8, 0 xec, 0 xa3, 0 x16, 0 x7a, 0 xe6, 0 x31, 0 x55,
0 x12, 0 xe5, 0 x9f, 0 x98, 0 xa7, 0 xc5, 0 x00, 0 x20,
0 x5e, 0 x5f, 0 x63, 0 xff, 0 x3b, 0 xb3, 0 x89, 0 xaf,
0 x1c, 0 x41, 0 xa2, 0 x1d, 0 x64, 0 x0d, 0 x86, 0 x15,
0 xc9, 0 xed, 0 x3f, 0 xbe, 0 xb0, 0 x5a, 0 xb6, 0 xac,
0 xb6, 0 x76, 0 x89, 0 xb5, 0 xea
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test5_confounder,
0 xca, 0 x7a, 0 x7a, 0 xb4, 0 xbe, 0 x19, 0 x2d, 0 xab,
0 xd6, 0 x03, 0 x50, 0 x6d, 0 xb1, 0 x9c, 0 x39, 0 xe2
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test5_basekey,
0 x78, 0 x24, 0 xf8, 0 xc1, 0 x6f, 0 x83, 0 xff, 0 x35,
0 x4c, 0 x6b, 0 xf7, 0 x51, 0 x5b, 0 x97, 0 x3f, 0 x43
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test5_expected_result,
0 xa2, 0 x6a, 0 x39, 0 x05, 0 xa4, 0 xff, 0 xd5, 0 x81,
0 x6b, 0 x7b, 0 x1e, 0 x27, 0 x38, 0 x0d, 0 x08, 0 x09,
0 x0c, 0 x8e, 0 xc1, 0 xf3, 0 x04, 0 x49, 0 x6e, 0 x1a,
0 xbd, 0 xcd, 0 x2b, 0 xdc, 0 xd1, 0 xdf, 0 xfc, 0 x66,
0 x09, 0 x89, 0 xe1, 0 x17, 0 xa7, 0 x13, 0 xdd, 0 xbb,
0 x57, 0 xa4, 0 x14, 0 x6c, 0 x15, 0 x87, 0 xcb, 0 xa4,
0 x35, 0 x66, 0 x65, 0 x59, 0 x1d, 0 x22, 0 x40, 0 x28,
0 x2f, 0 x58, 0 x42, 0 xb1, 0 x05, 0 xa5
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test6_confounder,
0 x3c, 0 xbb, 0 xd2, 0 xb4, 0 x59, 0 x17, 0 x94, 0 x10,
0 x67, 0 xf9, 0 x65, 0 x99, 0 xbb, 0 x98, 0 x92, 0 x6c
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test6_basekey,
0 xb6, 0 x1c, 0 x86, 0 xcc, 0 x4e, 0 x5d, 0 x27, 0 x57,
0 x54, 0 x5a, 0 xd4, 0 x23, 0 x39, 0 x9f, 0 xb7, 0 x03,
0 x1e, 0 xca, 0 xb9, 0 x13, 0 xcb, 0 xb9, 0 x00, 0 xbd,
0 x7a, 0 x3c, 0 x6d, 0 xd8, 0 xbf, 0 x92, 0 x01, 0 x5b
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test6_expected_result,
0 x03, 0 x88, 0 x6d, 0 x03, 0 x31, 0 x0b, 0 x47, 0 xa6,
0 xd8, 0 xf0, 0 x6d, 0 x7b, 0 x94, 0 xd1, 0 xdd, 0 x83,
0 x7e, 0 xcc, 0 xe3, 0 x15, 0 xef, 0 x65, 0 x2a, 0 xff,
0 x62, 0 x08, 0 x59, 0 xd9, 0 x4a, 0 x25, 0 x92, 0 x66
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test7_confounder,
0 xde, 0 xf4, 0 x87, 0 xfc, 0 xeb, 0 xe6, 0 xde, 0 x63,
0 x46, 0 xd4, 0 xda, 0 x45, 0 x21, 0 xbb, 0 xa2, 0 xd2
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test7_basekey,
0 x1b, 0 x97, 0 xfe, 0 x0a, 0 x19, 0 x0e, 0 x20, 0 x21,
0 xeb, 0 x30, 0 x75, 0 x3e, 0 x1b, 0 x6e, 0 x1e, 0 x77,
0 xb0, 0 x75, 0 x4b, 0 x1d, 0 x68, 0 x46, 0 x10, 0 x35,
0 x58, 0 x64, 0 x10, 0 x49, 0 x63, 0 x46, 0 x38, 0 x33
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test7_expected_result,
0 x2c, 0 x9c, 0 x15, 0 x70, 0 x13, 0 x3c, 0 x99, 0 xbf,
0 x6a, 0 x34, 0 xbc, 0 x1b, 0 x02, 0 x12, 0 x00, 0 x2f,
0 xd1, 0 x94, 0 x33, 0 x87, 0 x49, 0 xdb, 0 x41, 0 x35,
0 x49, 0 x7a, 0 x34, 0 x7c, 0 xfc, 0 xd9, 0 xd1, 0 x8a,
0 x12
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test8_confounder,
0 xad, 0 x4f, 0 xf9, 0 x04, 0 xd3, 0 x4e, 0 x55, 0 x53,
0 x84, 0 xb1, 0 x41, 0 x00, 0 xfc, 0 x46, 0 x5f, 0 x88
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test8_basekey,
0 x32, 0 x16, 0 x4c, 0 x5b, 0 x43, 0 x4d, 0 x1d, 0 x15,
0 x38, 0 xe4, 0 xcf, 0 xd9, 0 xbe, 0 x80, 0 x40, 0 xfe,
0 x8c, 0 x4a, 0 xc7, 0 xac, 0 xc4, 0 xb9, 0 x3d, 0 x33,
0 x14, 0 xd2, 0 x13, 0 x36, 0 x68, 0 x14, 0 x7a, 0 x05
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test8_expected_result,
0 x9c, 0 x6d, 0 xe7, 0 x5f, 0 x81, 0 x2d, 0 xe7, 0 xed,
0 x0d, 0 x28, 0 xb2, 0 x96, 0 x35, 0 x57, 0 xa1, 0 x15,
0 x64, 0 x09, 0 x98, 0 x27, 0 x5b, 0 x0a, 0 xf5, 0 x15,
0 x27, 0 x09, 0 x91, 0 x3f, 0 xf5, 0 x2a, 0 x2a, 0 x9c,
0 x8e, 0 x63, 0 xb8, 0 x72, 0 xf9, 0 x2e, 0 x64, 0 xc8,
0 x39
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test9_confounder,
0 xcf, 0 x9b, 0 xca, 0 x6d, 0 xf1, 0 x14, 0 x4e, 0 x0c,
0 x0a, 0 xf9, 0 xb8, 0 xf3, 0 x4c, 0 x90, 0 xd5, 0 x14
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test9_basekey,
0 xb0, 0 x38, 0 xb1, 0 x32, 0 xcd, 0 x8e, 0 x06, 0 x61,
0 x22, 0 x67, 0 xfa, 0 xb7, 0 x17, 0 x00, 0 x66, 0 xd8,
0 x8a, 0 xec, 0 xcb, 0 xa0, 0 xb7, 0 x44, 0 xbf, 0 xc6,
0 x0d, 0 xc8, 0 x9b, 0 xca, 0 x18, 0 x2d, 0 x07, 0 x15
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test9_expected_result,
0 xee, 0 xec, 0 x85, 0 xa9, 0 x81, 0 x3c, 0 xdc, 0 x53,
0 x67, 0 x72, 0 xab, 0 x9b, 0 x42, 0 xde, 0 xfc, 0 x57,
0 x06, 0 xf7, 0 x26, 0 xe9, 0 x75, 0 xdd, 0 xe0, 0 x5a,
0 x87, 0 xeb, 0 x54, 0 x06, 0 xea, 0 x32, 0 x4c, 0 xa1,
0 x85, 0 xc9, 0 x98, 0 x6b, 0 x42, 0 xaa, 0 xbe, 0 x79,
0 x4b, 0 x84, 0 x82, 0 x1b, 0 xee
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test10_confounder,
0 x64, 0 x4d, 0 xef, 0 x38, 0 xda, 0 x35, 0 x00, 0 x72,
0 x75, 0 x87, 0 x8d, 0 x21, 0 x68, 0 x55, 0 xe2, 0 x28
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test10_basekey,
0 xcc, 0 xfc, 0 xd3, 0 x49, 0 xbf, 0 x4c, 0 x66, 0 x77,
0 xe8, 0 x6e, 0 x4b, 0 x02, 0 xb8, 0 xea, 0 xb9, 0 x24,
0 xa5, 0 x46, 0 xac, 0 x73, 0 x1c, 0 xf9, 0 xbf, 0 x69,
0 x89, 0 xb9, 0 x96, 0 xe7, 0 xd6, 0 xbf, 0 xbb, 0 xa7
);
DEFINE_HEX_XDR_NETOBJ(rfc6803_enc_test10_expected_result,
0 x0e, 0 x44, 0 x68, 0 x09, 0 x85, 0 x85, 0 x5f, 0 x2d,
0 x1f, 0 x18, 0 x12, 0 x52, 0 x9c, 0 xa8, 0 x3b, 0 xfd,
0 x8e, 0 x34, 0 x9d, 0 xe6, 0 xfd, 0 x9a, 0 xda, 0 x0b,
0 xaa, 0 xa0, 0 x48, 0 xd6, 0 x8e, 0 x26, 0 x5f, 0 xeb,
0 xf3, 0 x4a, 0 xd1, 0 x25, 0 x5a, 0 x34, 0 x49, 0 x99,
0 xad, 0 x37, 0 x14, 0 x68, 0 x87, 0 xa6, 0 xc6, 0 x84,
0 x57, 0 x31, 0 xac, 0 x7f, 0 x46, 0 x37, 0 x6a, 0 x05,
0 x04, 0 xcd, 0 x06, 0 x57, 0 x14, 0 x74
);
static const struct gss_krb5_test_param rfc6803_encrypt_test_params[] = {
{
.desc = "Encrypt empty plaintext with camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.constant = 0 ,
.base_key = &rfc6803_enc_test1_basekey,
.plaintext = &rfc6803_enc_empty_plaintext,
.confounder = &rfc6803_enc_test1_confounder,
.expected_result = &rfc6803_enc_test1_expected_result,
},
{
.desc = "Encrypt 1 byte with camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.constant = 1 ,
.base_key = &rfc6803_enc_test2_basekey,
.plaintext = &rfc6803_enc_1byte_plaintext,
.confounder = &rfc6803_enc_test2_confounder,
.expected_result = &rfc6803_enc_test2_expected_result,
},
{
.desc = "Encrypt 9 bytes with camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.constant = 2 ,
.base_key = &rfc6803_enc_test3_basekey,
.plaintext = &rfc6803_enc_9byte_plaintext,
.confounder = &rfc6803_enc_test3_confounder,
.expected_result = &rfc6803_enc_test3_expected_result,
},
{
.desc = "Encrypt 13 bytes with camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.constant = 3 ,
.base_key = &rfc6803_enc_test4_basekey,
.plaintext = &rfc6803_enc_13byte_plaintext,
.confounder = &rfc6803_enc_test4_confounder,
.expected_result = &rfc6803_enc_test4_expected_result,
},
{
.desc = "Encrypt 30 bytes with camellia128-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.constant = 4 ,
.base_key = &rfc6803_enc_test5_basekey,
.plaintext = &rfc6803_enc_30byte_plaintext,
.confounder = &rfc6803_enc_test5_confounder,
.expected_result = &rfc6803_enc_test5_expected_result,
},
{
.desc = "Encrypt empty plaintext with camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.constant = 0 ,
.base_key = &rfc6803_enc_test6_basekey,
.plaintext = &rfc6803_enc_empty_plaintext,
.confounder = &rfc6803_enc_test6_confounder,
.expected_result = &rfc6803_enc_test6_expected_result,
},
{
.desc = "Encrypt 1 byte with camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.constant = 1 ,
.base_key = &rfc6803_enc_test7_basekey,
.plaintext = &rfc6803_enc_1byte_plaintext,
.confounder = &rfc6803_enc_test7_confounder,
.expected_result = &rfc6803_enc_test7_expected_result,
},
{
.desc = "Encrypt 9 bytes with camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.constant = 2 ,
.base_key = &rfc6803_enc_test8_basekey,
.plaintext = &rfc6803_enc_9byte_plaintext,
.confounder = &rfc6803_enc_test8_confounder,
.expected_result = &rfc6803_enc_test8_expected_result,
},
{
.desc = "Encrypt 13 bytes with camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.constant = 3 ,
.base_key = &rfc6803_enc_test9_basekey,
.plaintext = &rfc6803_enc_13byte_plaintext,
.confounder = &rfc6803_enc_test9_confounder,
.expected_result = &rfc6803_enc_test9_expected_result,
},
{
.desc = "Encrypt 30 bytes with camellia256-cts-cmac" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.constant = 4 ,
.base_key = &rfc6803_enc_test10_basekey,
.plaintext = &rfc6803_enc_30byte_plaintext,
.confounder = &rfc6803_enc_test10_confounder,
.expected_result = &rfc6803_enc_test10_expected_result,
},
};
/* Creates the function rfc6803_encrypt_gen_params */
KUNIT_ARRAY_PARAM(rfc6803_encrypt, rfc6803_encrypt_test_params,
gss_krb5_get_desc);
static void rfc6803_encrypt_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
const struct gss_krb5_enctype *gk5e;
struct xdr_netobj Ke, Ki, checksum;
u8 usage_data[GSS_KRB5_K5CLENGTH];
struct xdr_netobj usage = {
.data = usage_data,
.len = sizeof (usage_data),
};
struct crypto_ahash *ahash_tfm;
unsigned int blocksize;
struct xdr_buf buf;
void *text;
size_t len;
u32 err;
/* Arrange */
gk5e = gss_krb5_lookup_enctype(param->enctype);
if (!gk5e)
kunit_skip(test, "Encryption type is not available" );
memset(usage_data, 0 , sizeof (usage_data));
usage.data[3 ] = param->constant;
Ke.len = gk5e->Ke_length;
Ke.data = kunit_kzalloc(test, Ke.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ke.data);
usage.data[4 ] = KEY_USAGE_SEED_ENCRYPTION;
err = gk5e->derive_key(gk5e, param->base_key, &Ke, &usage, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0 );
cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
err = crypto_sync_skcipher_setkey(cbc_tfm, Ke.data, Ke.len);
KUNIT_ASSERT_EQ(test, err, 0 );
cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
err = crypto_sync_skcipher_setkey(cts_tfm, Ke.data, Ke.len);
KUNIT_ASSERT_EQ(test, err, 0 );
blocksize = crypto_sync_skcipher_blocksize(cts_tfm);
len = param->confounder->len + param->plaintext->len + blocksize;
text = kunit_kzalloc(test, len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
memcpy(text, param->confounder->data, param->confounder->len);
memcpy(text + param->confounder->len, param->plaintext->data,
param->plaintext->len);
memset(&buf, 0 , sizeof (buf));
buf.head[0 ].iov_base = text;
buf.head[0 ].iov_len = param->confounder->len + param->plaintext->len;
buf.len = buf.head[0 ].iov_len;
checksum.len = gk5e->cksumlength;
checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
Ki.len = gk5e->Ki_length;
Ki.data = kunit_kzalloc(test, Ki.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ki.data);
usage.data[4 ] = KEY_USAGE_SEED_INTEGRITY;
err = gk5e->derive_key(gk5e, param->base_key, &Ki,
&usage, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0 );
ahash_tfm = crypto_alloc_ahash(gk5e->cksum_name, 0 , CRYPTO_ALG_ASYNC);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ahash_tfm);
err = crypto_ahash_setkey(ahash_tfm, Ki.data, Ki.len);
KUNIT_ASSERT_EQ(test, err, 0 );
/* Act */
err = gss_krb5_checksum(ahash_tfm, NULL, 0 , &buf, 0 , &checksum);
KUNIT_ASSERT_EQ(test, err, 0 );
err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0 , &buf, NULL, NULL, 0 );
KUNIT_ASSERT_EQ(test, err, 0 );
/* Assert */
KUNIT_EXPECT_EQ_MSG(test, param->expected_result->len,
buf.len + checksum.len,
"ciphertext length mismatch" );
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data,
buf.head[0 ].iov_base, buf.len), 0 ,
"encrypted result mismatch" );
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data +
(param->expected_result->len - checksum.len),
checksum.data, checksum.len), 0 ,
"HMAC mismatch" );
crypto_free_ahash(ahash_tfm);
crypto_free_sync_skcipher(cts_tfm);
crypto_free_sync_skcipher(cbc_tfm);
}
static struct kunit_case rfc6803_test_cases[] = {
{
.name = "RFC 6803 key derivation" ,
.run_case = kdf_case,
.generate_params = rfc6803_kdf_gen_params,
},
{
.name = "RFC 6803 checksum" ,
.run_case = checksum_case,
.generate_params = rfc6803_checksum_gen_params,
},
{
.name = "RFC 6803 encryption" ,
.run_case = rfc6803_encrypt_case,
.generate_params = rfc6803_encrypt_gen_params,
},
{}
};
static struct kunit_suite rfc6803_suite = {
.name = "RFC 6803 suite" ,
.test_cases = rfc6803_test_cases,
};
/*
* From RFC 8009 Appendix A. Test Vectors
*
* Sample results for SHA-2 enctype key derivation
*
* This test material is copyright (c) 2016 IETF Trust and the
* persons identified as the document authors. All rights reserved.
*/
DEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_basekey,
0 x37, 0 x05, 0 xd9, 0 x60, 0 x80, 0 xc1, 0 x77, 0 x28,
0 xa0, 0 xe8, 0 x00, 0 xea, 0 xb6, 0 xe0, 0 xd2, 0 x3c
);
DEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_Kc,
0 xb3, 0 x1a, 0 x01, 0 x8a, 0 x48, 0 xf5, 0 x47, 0 x76,
0 xf4, 0 x03, 0 xe9, 0 xa3, 0 x96, 0 x32, 0 x5d, 0 xc3
);
DEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_Ke,
0 x9b, 0 x19, 0 x7d, 0 xd1, 0 xe8, 0 xc5, 0 x60, 0 x9d,
0 x6e, 0 x67, 0 xc3, 0 xe3, 0 x7c, 0 x62, 0 xc7, 0 x2e
);
DEFINE_HEX_XDR_NETOBJ(aes128_cts_hmac_sha256_128_Ki,
0 x9f, 0 xda, 0 x0e, 0 x56, 0 xab, 0 x2d, 0 x85, 0 xe1,
0 x56, 0 x9a, 0 x68, 0 x86, 0 x96, 0 xc2, 0 x6a, 0 x6c
);
DEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_basekey,
0 x6d, 0 x40, 0 x4d, 0 x37, 0 xfa, 0 xf7, 0 x9f, 0 x9d,
0 xf0, 0 xd3, 0 x35, 0 x68, 0 xd3, 0 x20, 0 x66, 0 x98,
0 x00, 0 xeb, 0 x48, 0 x36, 0 x47, 0 x2e, 0 xa8, 0 xa0,
0 x26, 0 xd1, 0 x6b, 0 x71, 0 x82, 0 x46, 0 x0c, 0 x52
);
DEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_Kc,
0 xef, 0 x57, 0 x18, 0 xbe, 0 x86, 0 xcc, 0 x84, 0 x96,
0 x3d, 0 x8b, 0 xbb, 0 x50, 0 x31, 0 xe9, 0 xf5, 0 xc4,
0 xba, 0 x41, 0 xf2, 0 x8f, 0 xaf, 0 x69, 0 xe7, 0 x3d
);
DEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_Ke,
0 x56, 0 xab, 0 x22, 0 xbe, 0 xe6, 0 x3d, 0 x82, 0 xd7,
0 xbc, 0 x52, 0 x27, 0 xf6, 0 x77, 0 x3f, 0 x8e, 0 xa7,
0 xa5, 0 xeb, 0 x1c, 0 x82, 0 x51, 0 x60, 0 xc3, 0 x83,
0 x12, 0 x98, 0 x0c, 0 x44, 0 x2e, 0 x5c, 0 x7e, 0 x49
);
DEFINE_HEX_XDR_NETOBJ(aes256_cts_hmac_sha384_192_Ki,
0 x69, 0 xb1, 0 x65, 0 x14, 0 xe3, 0 xcd, 0 x8e, 0 x56,
0 xb8, 0 x20, 0 x10, 0 xd5, 0 xc7, 0 x30, 0 x12, 0 xb6,
0 x22, 0 xc4, 0 xd0, 0 x0f, 0 xfc, 0 x23, 0 xed, 0 x1f
);
static const struct gss_krb5_test_param rfc8009_kdf_test_params[] = {
{
.desc = "Derive Kc subkey for aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.usage = &usage_checksum,
.expected_result = &aes128_cts_hmac_sha256_128_Kc,
},
{
.desc = "Derive Ke subkey for aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.usage = &usage_encryption,
.expected_result = &aes128_cts_hmac_sha256_128_Ke,
},
{
.desc = "Derive Ki subkey for aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.usage = &usage_integrity,
.expected_result = &aes128_cts_hmac_sha256_128_Ki,
},
{
.desc = "Derive Kc subkey for aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.usage = &usage_checksum,
.expected_result = &aes256_cts_hmac_sha384_192_Kc,
},
{
.desc = "Derive Ke subkey for aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.usage = &usage_encryption,
.expected_result = &aes256_cts_hmac_sha384_192_Ke,
},
{
.desc = "Derive Ki subkey for aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.usage = &usage_integrity,
.expected_result = &aes256_cts_hmac_sha384_192_Ki,
},
};
/* Creates the function rfc8009_kdf_gen_params */
KUNIT_ARRAY_PARAM(rfc8009_kdf, rfc8009_kdf_test_params, gss_krb5_get_desc);
/*
* From RFC 8009 Appendix A. Test Vectors
*
* These sample checksums use the above sample key derivation results,
* including use of the same base-key and key usage values.
*
* This test material is copyright (c) 2016 IETF Trust and the
* persons identified as the document authors. All rights reserved.
*/
DEFINE_HEX_XDR_NETOBJ(rfc8009_checksum_plaintext,
0 x00, 0 x01, 0 x02, 0 x03, 0 x04, 0 x05, 0 x06, 0 x07,
0 x08, 0 x09, 0 x0a, 0 x0b, 0 x0c, 0 x0d, 0 x0e, 0 x0f,
0 x10, 0 x11, 0 x12, 0 x13, 0 x14
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_checksum_test1_expected_result,
0 xd7, 0 x83, 0 x67, 0 x18, 0 x66, 0 x43, 0 xd6, 0 x7b,
0 x41, 0 x1c, 0 xba, 0 x91, 0 x39, 0 xfc, 0 x1d, 0 xee
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_checksum_test2_expected_result,
0 x45, 0 xee, 0 x79, 0 x15, 0 x67, 0 xee, 0 xfc, 0 xa3,
0 x7f, 0 x4a, 0 xc1, 0 xe0, 0 x22, 0 x2d, 0 xe8, 0 x0d,
0 x43, 0 xc3, 0 xbf, 0 xa0, 0 x66, 0 x99, 0 x67, 0 x2a
);
static const struct gss_krb5_test_param rfc8009_checksum_test_params[] = {
{
.desc = "Checksum with aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.usage = &usage_checksum,
.plaintext = &rfc8009_checksum_plaintext,
.expected_result = &rfc8009_checksum_test1_expected_result,
},
{
.desc = "Checksum with aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.usage = &usage_checksum,
.plaintext = &rfc8009_checksum_plaintext,
.expected_result = &rfc8009_checksum_test2_expected_result,
},
};
/* Creates the function rfc8009_checksum_gen_params */
KUNIT_ARRAY_PARAM(rfc8009_checksum, rfc8009_checksum_test_params,
gss_krb5_get_desc);
/*
* From RFC 8009 Appendix A. Test Vectors
*
* Sample encryptions (all using the default cipher state):
* --------------------------------------------------------
*
* These sample encryptions use the above sample key derivation results,
* including use of the same base-key and key usage values.
*
* This test material is copyright (c) 2016 IETF Trust and the
* persons identified as the document authors. All rights reserved.
*/
static const struct xdr_netobj rfc8009_enc_empty_plaintext = {
.len = 0 ,
};
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_short_plaintext,
0 x00, 0 x01, 0 x02, 0 x03, 0 x04, 0 x05
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_block_plaintext,
0 x00, 0 x01, 0 x02, 0 x03, 0 x04, 0 x05, 0 x06, 0 x07,
0 x08, 0 x09, 0 x0a, 0 x0b, 0 x0c, 0 x0d, 0 x0e, 0 x0f
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_long_plaintext,
0 x00, 0 x01, 0 x02, 0 x03, 0 x04, 0 x05, 0 x06, 0 x07,
0 x08, 0 x09, 0 x0a, 0 x0b, 0 x0c, 0 x0d, 0 x0e, 0 x0f,
0 x10, 0 x11, 0 x12, 0 x13, 0 x14
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test1_confounder,
0 x7e, 0 x58, 0 x95, 0 xea, 0 xf2, 0 x67, 0 x24, 0 x35,
0 xba, 0 xd8, 0 x17, 0 xf5, 0 x45, 0 xa3, 0 x71, 0 x48
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test1_expected_result,
0 xef, 0 x85, 0 xfb, 0 x89, 0 x0b, 0 xb8, 0 x47, 0 x2f,
0 x4d, 0 xab, 0 x20, 0 x39, 0 x4d, 0 xca, 0 x78, 0 x1d
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test1_expected_hmac,
0 xad, 0 x87, 0 x7e, 0 xda, 0 x39, 0 xd5, 0 x0c, 0 x87,
0 x0c, 0 x0d, 0 x5a, 0 x0a, 0 x8e, 0 x48, 0 xc7, 0 x18
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test2_confounder,
0 x7b, 0 xca, 0 x28, 0 x5e, 0 x2f, 0 xd4, 0 x13, 0 x0f,
0 xb5, 0 x5b, 0 x1a, 0 x5c, 0 x83, 0 xbc, 0 x5b, 0 x24
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test2_expected_result,
0 x84, 0 xd7, 0 xf3, 0 x07, 0 x54, 0 xed, 0 x98, 0 x7b,
0 xab, 0 x0b, 0 xf3, 0 x50, 0 x6b, 0 xeb, 0 x09, 0 xcf,
0 xb5, 0 x54, 0 x02, 0 xce, 0 xf7, 0 xe6
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test2_expected_hmac,
0 x87, 0 x7c, 0 xe9, 0 x9e, 0 x24, 0 x7e, 0 x52, 0 xd1,
0 x6e, 0 xd4, 0 x42, 0 x1d, 0 xfd, 0 xf8, 0 x97, 0 x6c
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test3_confounder,
0 x56, 0 xab, 0 x21, 0 x71, 0 x3f, 0 xf6, 0 x2c, 0 x0a,
0 x14, 0 x57, 0 x20, 0 x0f, 0 x6f, 0 xa9, 0 x94, 0 x8f
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test3_expected_result,
0 x35, 0 x17, 0 xd6, 0 x40, 0 xf5, 0 x0d, 0 xdc, 0 x8a,
0 xd3, 0 x62, 0 x87, 0 x22, 0 xb3, 0 x56, 0 x9d, 0 x2a,
0 xe0, 0 x74, 0 x93, 0 xfa, 0 x82, 0 x63, 0 x25, 0 x40,
0 x80, 0 xea, 0 x65, 0 xc1, 0 x00, 0 x8e, 0 x8f, 0 xc2
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test3_expected_hmac,
0 x95, 0 xfb, 0 x48, 0 x52, 0 xe7, 0 xd8, 0 x3e, 0 x1e,
0 x7c, 0 x48, 0 xc3, 0 x7e, 0 xeb, 0 xe6, 0 xb0, 0 xd3
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test4_confounder,
0 xa7, 0 xa4, 0 xe2, 0 x9a, 0 x47, 0 x28, 0 xce, 0 x10,
0 x66, 0 x4f, 0 xb6, 0 x4e, 0 x49, 0 xad, 0 x3f, 0 xac
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test4_expected_result,
0 x72, 0 x0f, 0 x73, 0 xb1, 0 x8d, 0 x98, 0 x59, 0 xcd,
0 x6c, 0 xcb, 0 x43, 0 x46, 0 x11, 0 x5c, 0 xd3, 0 x36,
0 xc7, 0 x0f, 0 x58, 0 xed, 0 xc0, 0 xc4, 0 x43, 0 x7c,
0 x55, 0 x73, 0 x54, 0 x4c, 0 x31, 0 xc8, 0 x13, 0 xbc,
0 xe1, 0 xe6, 0 xd0, 0 x72, 0 xc1
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test4_expected_hmac,
0 x86, 0 xb3, 0 x9a, 0 x41, 0 x3c, 0 x2f, 0 x92, 0 xca,
0 x9b, 0 x83, 0 x34, 0 xa2, 0 x87, 0 xff, 0 xcb, 0 xfc
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test5_confounder,
0 xf7, 0 x64, 0 xe9, 0 xfa, 0 x15, 0 xc2, 0 x76, 0 x47,
0 x8b, 0 x2c, 0 x7d, 0 x0c, 0 x4e, 0 x5f, 0 x58, 0 xe4
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test5_expected_result,
0 x41, 0 xf5, 0 x3f, 0 xa5, 0 xbf, 0 xe7, 0 x02, 0 x6d,
0 x91, 0 xfa, 0 xf9, 0 xbe, 0 x95, 0 x91, 0 x95, 0 xa0
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test5_expected_hmac,
0 x58, 0 x70, 0 x72, 0 x73, 0 xa9, 0 x6a, 0 x40, 0 xf0,
0 xa0, 0 x19, 0 x60, 0 x62, 0 x1a, 0 xc6, 0 x12, 0 x74,
0 x8b, 0 x9b, 0 xbf, 0 xbe, 0 x7e, 0 xb4, 0 xce, 0 x3c
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test6_confounder,
0 xb8, 0 x0d, 0 x32, 0 x51, 0 xc1, 0 xf6, 0 x47, 0 x14,
0 x94, 0 x25, 0 x6f, 0 xfe, 0 x71, 0 x2d, 0 x0b, 0 x9a
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test6_expected_result,
0 x4e, 0 xd7, 0 xb3, 0 x7c, 0 x2b, 0 xca, 0 xc8, 0 xf7,
0 x4f, 0 x23, 0 xc1, 0 xcf, 0 x07, 0 xe6, 0 x2b, 0 xc7,
0 xb7, 0 x5f, 0 xb3, 0 xf6, 0 x37, 0 xb9
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test6_expected_hmac,
0 xf5, 0 x59, 0 xc7, 0 xf6, 0 x64, 0 xf6, 0 x9e, 0 xab,
0 x7b, 0 x60, 0 x92, 0 x23, 0 x75, 0 x26, 0 xea, 0 x0d,
0 x1f, 0 x61, 0 xcb, 0 x20, 0 xd6, 0 x9d, 0 x10, 0 xf2
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test7_confounder,
0 x53, 0 xbf, 0 x8a, 0 x0d, 0 x10, 0 x52, 0 x65, 0 xd4,
0 xe2, 0 x76, 0 x42, 0 x86, 0 x24, 0 xce, 0 x5e, 0 x63
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test7_expected_result,
0 xbc, 0 x47, 0 xff, 0 xec, 0 x79, 0 x98, 0 xeb, 0 x91,
0 xe8, 0 x11, 0 x5c, 0 xf8, 0 xd1, 0 x9d, 0 xac, 0 x4b,
0 xbb, 0 xe2, 0 xe1, 0 x63, 0 xe8, 0 x7d, 0 xd3, 0 x7f,
0 x49, 0 xbe, 0 xca, 0 x92, 0 x02, 0 x77, 0 x64, 0 xf6
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test7_expected_hmac,
0 x8c, 0 xf5, 0 x1f, 0 x14, 0 xd7, 0 x98, 0 xc2, 0 x27,
0 x3f, 0 x35, 0 xdf, 0 x57, 0 x4d, 0 x1f, 0 x93, 0 x2e,
0 x40, 0 xc4, 0 xff, 0 x25, 0 x5b, 0 x36, 0 xa2, 0 x66
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test8_confounder,
0 x76, 0 x3e, 0 x65, 0 x36, 0 x7e, 0 x86, 0 x4f, 0 x02,
0 xf5, 0 x51, 0 x53, 0 xc7, 0 xe3, 0 xb5, 0 x8a, 0 xf1
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test8_expected_result,
0 x40, 0 x01, 0 x3e, 0 x2d, 0 xf5, 0 x8e, 0 x87, 0 x51,
0 x95, 0 x7d, 0 x28, 0 x78, 0 xbc, 0 xd2, 0 xd6, 0 xfe,
0 x10, 0 x1c, 0 xcf, 0 xd5, 0 x56, 0 xcb, 0 x1e, 0 xae,
0 x79, 0 xdb, 0 x3c, 0 x3e, 0 xe8, 0 x64, 0 x29, 0 xf2,
0 xb2, 0 xa6, 0 x02, 0 xac, 0 x86
);
DEFINE_HEX_XDR_NETOBJ(rfc8009_enc_test8_expected_hmac,
0 xfe, 0 xf6, 0 xec, 0 xb6, 0 x47, 0 xd6, 0 x29, 0 x5f,
0 xae, 0 x07, 0 x7a, 0 x1f, 0 xeb, 0 x51, 0 x75, 0 x08,
0 xd2, 0 xc1, 0 x6b, 0 x41, 0 x92, 0 xe0, 0 x1f, 0 x62
);
static const struct gss_krb5_test_param rfc8009_encrypt_test_params[] = {
{
.desc = "Encrypt empty plaintext with aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.plaintext = &rfc8009_enc_empty_plaintext,
.confounder = &rfc8009_enc_test1_confounder,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.expected_result = &rfc8009_enc_test1_expected_result,
.expected_hmac = &rfc8009_enc_test1_expected_hmac,
},
{
.desc = "Encrypt short plaintext with aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.plaintext = &rfc8009_enc_short_plaintext,
.confounder = &rfc8009_enc_test2_confounder,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.expected_result = &rfc8009_enc_test2_expected_result,
.expected_hmac = &rfc8009_enc_test2_expected_hmac,
},
{
.desc = "Encrypt block plaintext with aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.plaintext = &rfc8009_enc_block_plaintext,
.confounder = &rfc8009_enc_test3_confounder,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.expected_result = &rfc8009_enc_test3_expected_result,
.expected_hmac = &rfc8009_enc_test3_expected_hmac,
},
{
.desc = "Encrypt long plaintext with aes128-cts-hmac-sha256-128" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.plaintext = &rfc8009_enc_long_plaintext,
.confounder = &rfc8009_enc_test4_confounder,
.base_key = &aes128_cts_hmac_sha256_128_basekey,
.expected_result = &rfc8009_enc_test4_expected_result,
.expected_hmac = &rfc8009_enc_test4_expected_hmac,
},
{
.desc = "Encrypt empty plaintext with aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.plaintext = &rfc8009_enc_empty_plaintext,
.confounder = &rfc8009_enc_test5_confounder,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.expected_result = &rfc8009_enc_test5_expected_result,
.expected_hmac = &rfc8009_enc_test5_expected_hmac,
},
{
.desc = "Encrypt short plaintext with aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.plaintext = &rfc8009_enc_short_plaintext,
.confounder = &rfc8009_enc_test6_confounder,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.expected_result = &rfc8009_enc_test6_expected_result,
.expected_hmac = &rfc8009_enc_test6_expected_hmac,
},
{
.desc = "Encrypt block plaintext with aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.plaintext = &rfc8009_enc_block_plaintext,
.confounder = &rfc8009_enc_test7_confounder,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.expected_result = &rfc8009_enc_test7_expected_result,
.expected_hmac = &rfc8009_enc_test7_expected_hmac,
},
{
.desc = "Encrypt long plaintext with aes256-cts-hmac-sha384-192" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.plaintext = &rfc8009_enc_long_plaintext,
.confounder = &rfc8009_enc_test8_confounder,
.base_key = &aes256_cts_hmac_sha384_192_basekey,
.expected_result = &rfc8009_enc_test8_expected_result,
.expected_hmac = &rfc8009_enc_test8_expected_hmac,
},
};
/* Creates the function rfc8009_encrypt_gen_params */
KUNIT_ARRAY_PARAM(rfc8009_encrypt, rfc8009_encrypt_test_params,
gss_krb5_get_desc);
static void rfc8009_encrypt_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
const struct gss_krb5_enctype *gk5e;
struct xdr_netobj Ke, Ki, checksum;
u8 usage_data[GSS_KRB5_K5CLENGTH];
struct xdr_netobj usage = {
.data = usage_data,
.len = sizeof (usage_data),
};
struct crypto_ahash *ahash_tfm;
struct xdr_buf buf;
void *text;
size_t len;
u32 err;
/* Arrange */
gk5e = gss_krb5_lookup_enctype(param->enctype);
if (!gk5e)
kunit_skip(test, "Encryption type is not available" );
*(__be32 *)usage.data = cpu_to_be32(2 );
Ke.len = gk5e->Ke_length;
Ke.data = kunit_kzalloc(test, Ke.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ke.data);
usage.data[4 ] = KEY_USAGE_SEED_ENCRYPTION;
err = gk5e->derive_key(gk5e, param->base_key, &Ke,
&usage, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0 );
cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
err = crypto_sync_skcipher_setkey(cbc_tfm, Ke.data, Ke.len);
KUNIT_ASSERT_EQ(test, err, 0 );
cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
err = crypto_sync_skcipher_setkey(cts_tfm, Ke.data, Ke.len);
KUNIT_ASSERT_EQ(test, err, 0 );
len = param->confounder->len + param->plaintext->len;
text = kunit_kzalloc(test, len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
memcpy(text, param->confounder->data, param->confounder->len);
memcpy(text + param->confounder->len, param->plaintext->data,
param->plaintext->len);
memset(&buf, 0 , sizeof (buf));
buf.head[0 ].iov_base = text;
buf.head[0 ].iov_len = param->confounder->len + param->plaintext->len;
buf.len = buf.head[0 ].iov_len;
checksum.len = gk5e->cksumlength;
checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
Ki.len = gk5e->Ki_length;
Ki.data = kunit_kzalloc(test, Ki.len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, Ki.data);
usage.data[4 ] = KEY_USAGE_SEED_INTEGRITY;
err = gk5e->derive_key(gk5e, param->base_key, &Ki,
&usage, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0 );
ahash_tfm = crypto_alloc_ahash(gk5e->cksum_name, 0 , CRYPTO_ALG_ASYNC);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ahash_tfm);
err = crypto_ahash_setkey(ahash_tfm, Ki.data, Ki.len);
KUNIT_ASSERT_EQ(test, err, 0 );
/* Act */
err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0 , &buf, NULL, NULL, 0 );
KUNIT_ASSERT_EQ(test, err, 0 );
err = krb5_etm_checksum(cts_tfm, ahash_tfm, &buf, 0 , &checksum);
KUNIT_ASSERT_EQ(test, err, 0 );
/* Assert */
KUNIT_EXPECT_EQ_MSG(test,
param->expected_result->len, buf.len,
"ciphertext length mismatch" );
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->expected_result->data,
buf.head[0 ].iov_base,
param->expected_result->len), 0 ,
"ciphertext mismatch" );
KUNIT_EXPECT_EQ_MSG(test, memcmp(param->expected_hmac->data,
checksum.data,
checksum.len), 0 ,
"HMAC mismatch" );
crypto_free_ahash(ahash_tfm);
crypto_free_sync_skcipher(cts_tfm);
crypto_free_sync_skcipher(cbc_tfm);
}
static struct kunit_case rfc8009_test_cases[] = {
{
.name = "RFC 8009 key derivation" ,
.run_case = kdf_case,
.generate_params = rfc8009_kdf_gen_params,
},
{
.name = "RFC 8009 checksum" ,
.run_case = checksum_case,
.generate_params = rfc8009_checksum_gen_params,
},
{
.name = "RFC 8009 encryption" ,
.run_case = rfc8009_encrypt_case,
.generate_params = rfc8009_encrypt_gen_params,
},
{}
};
static struct kunit_suite rfc8009_suite = {
.name = "RFC 8009 suite" ,
.test_cases = rfc8009_test_cases,
};
/*
* Encryption self-tests
*/
DEFINE_STR_XDR_NETOBJ(encrypt_selftest_plaintext,
"This is the plaintext for the encryption self-test." );
static const struct gss_krb5_test_param encrypt_selftest_params[] = {
{
.desc = "aes128-cts-hmac-sha1-96 encryption self-test" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &encrypt_selftest_plaintext,
},
{
.desc = "aes256-cts-hmac-sha1-96 encryption self-test" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA1_96,
.Ke = &rfc3962_encryption_key,
.plaintext = &encrypt_selftest_plaintext,
},
{
.desc = "camellia128-cts-cmac encryption self-test" ,
.enctype = ENCTYPE_CAMELLIA128_CTS_CMAC,
.Ke = &camellia128_cts_cmac_Ke,
.plaintext = &encrypt_selftest_plaintext,
},
{
.desc = "camellia256-cts-cmac encryption self-test" ,
.enctype = ENCTYPE_CAMELLIA256_CTS_CMAC,
.Ke = &camellia256_cts_cmac_Ke,
.plaintext = &encrypt_selftest_plaintext,
},
{
.desc = "aes128-cts-hmac-sha256-128 encryption self-test" ,
.enctype = ENCTYPE_AES128_CTS_HMAC_SHA256_128,
.Ke = &aes128_cts_hmac_sha256_128_Ke,
.plaintext = &encrypt_selftest_plaintext,
},
{
.desc = "aes256-cts-hmac-sha384-192 encryption self-test" ,
.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192,
.Ke = &aes256_cts_hmac_sha384_192_Ke,
.plaintext = &encrypt_selftest_plaintext,
},
};
/* Creates the function encrypt_selftest_gen_params */
KUNIT_ARRAY_PARAM(encrypt_selftest, encrypt_selftest_params,
gss_krb5_get_desc);
/*
* Encrypt and decrypt plaintext, and ensure the input plaintext
* matches the output plaintext. A confounder is not added in this
* case.
*/
static void encrypt_selftest_case(struct kunit *test)
{
const struct gss_krb5_test_param *param = test->param_value;
struct crypto_sync_skcipher *cts_tfm, *cbc_tfm;
const struct gss_krb5_enctype *gk5e;
struct xdr_buf buf;
void *text;
int err;
/* Arrange */
gk5e = gss_krb5_lookup_enctype(param->enctype);
if (!gk5e)
kunit_skip(test, "Encryption type is not available" );
cbc_tfm = crypto_alloc_sync_skcipher(gk5e->aux_cipher, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cbc_tfm);
err = crypto_sync_skcipher_setkey(cbc_tfm, param->Ke->data, param->Ke->len);
KUNIT_ASSERT_EQ(test, err, 0 );
cts_tfm = crypto_alloc_sync_skcipher(gk5e->encrypt_name, 0 , 0 );
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cts_tfm);
err = crypto_sync_skcipher_setkey(cts_tfm, param->Ke->data, param->Ke->len);
KUNIT_ASSERT_EQ(test, err, 0 );
text = kunit_kzalloc(test, roundup(param->plaintext->len,
crypto_sync_skcipher_blocksize(cbc_tfm)),
GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, text);
memcpy(text, param->plaintext->data, param->plaintext->len);
memset(&buf, 0 , sizeof (buf));
buf.head[0 ].iov_base = text;
buf.head[0 ].iov_len = param->plaintext->len;
buf.len = buf.head[0 ].iov_len;
/* Act */
err = krb5_cbc_cts_encrypt(cts_tfm, cbc_tfm, 0 , &buf, NULL, NULL, 0 );
KUNIT_ASSERT_EQ(test, err, 0 );
err = krb5_cbc_cts_decrypt(cts_tfm, cbc_tfm, 0 , &buf);
KUNIT_ASSERT_EQ(test, err, 0 );
/* Assert */
KUNIT_EXPECT_EQ_MSG(test,
param->plaintext->len, buf.len,
"length mismatch" );
KUNIT_EXPECT_EQ_MSG(test,
memcmp(param->plaintext->data,
buf.head[0 ].iov_base, buf.len), 0 ,
"plaintext mismatch" );
crypto_free_sync_skcipher(cts_tfm);
crypto_free_sync_skcipher(cbc_tfm);
}
static struct kunit_case encryption_test_cases[] = {
{
.name = "Encryption self-tests" ,
.run_case = encrypt_selftest_case,
.generate_params = encrypt_selftest_gen_params,
},
{}
};
static struct kunit_suite encryption_test_suite = {
.name = "Encryption test suite" ,
.test_cases = encryption_test_cases,
};
kunit_test_suites(&rfc3961_suite,
&rfc3962_suite,
&rfc6803_suite,
&rfc8009_suite,
&encryption_test_suite);
MODULE_DESCRIPTION("Test RPCSEC GSS Kerberos 5 functions" );
MODULE_LICENSE("GPL" );
Messung V0.5 in Prozent C=96 H=89 G=92
¤ Dauer der Verarbeitung: 0.29 Sekunden
(vorverarbeitet am 2026-06-07)
¤
*© Formatika GbR, Deutschland