~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/mptcp/crypto_test.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <kunit/test.h>
  3 
  4 #include "protocol.h"
  5 
  6 struct test_case {
  7         char *key;
  8         char *msg;
  9         char *result;
 10 };
 11 
 12 /* we can't reuse RFC 4231 test vectors, as we have constraint on the
 13  * input and key size.
 14  */
 15 static struct test_case tests[] = {
 16         {
 17                 .key = "0b0b0b0b0b0b0b0b",
 18                 .msg = "48692054",
 19                 .result = "8385e24fb4235ac37556b6b886db106284a1da671699f46db1f235ec622dcafa",
 20         },
 21         {
 22                 .key = "aaaaaaaaaaaaaaaa",
 23                 .msg = "dddddddd",
 24                 .result = "2c5e219164ff1dca1c4a92318d847bb6b9d44492984e1eb71aff9022f71046e9",
 25         },
 26         {
 27                 .key = "0102030405060708",
 28                 .msg = "cdcdcdcd",
 29                 .result = "e73b9ba9969969cefb04aa0d6df18ec2fcc075b6f23b4d8c4da736a5dbbc6e7d",
 30         },
 31 };
 32 
 33 static void mptcp_crypto_test_basic(struct kunit *test)
 34 {
 35         char hmac[32], hmac_hex[65];
 36         u32 nonce1, nonce2;
 37         u64 key1, key2;
 38         u8 msg[8];
 39         int i, j;
 40 
 41         for (i = 0; i < ARRAY_SIZE(tests); ++i) {
 42                 /* mptcp hmap will convert to be before computing the hmac */
 43                 key1 = be64_to_cpu(*((__be64 *)&tests[i].key[0]));
 44                 key2 = be64_to_cpu(*((__be64 *)&tests[i].key[8]));
 45                 nonce1 = be32_to_cpu(*((__be32 *)&tests[i].msg[0]));
 46                 nonce2 = be32_to_cpu(*((__be32 *)&tests[i].msg[4]));
 47 
 48                 put_unaligned_be32(nonce1, &msg[0]);
 49                 put_unaligned_be32(nonce2, &msg[4]);
 50 
 51                 mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac);
 52                 for (j = 0; j < 32; ++j)
 53                         sprintf(&hmac_hex[j << 1], "%02x", hmac[j] & 0xff);
 54                 hmac_hex[64] = 0;
 55 
 56                 KUNIT_EXPECT_STREQ(test, &hmac_hex[0], tests[i].result);
 57         }
 58 }
 59 
 60 static struct kunit_case mptcp_crypto_test_cases[] = {
 61         KUNIT_CASE(mptcp_crypto_test_basic),
 62         {}
 63 };
 64 
 65 static struct kunit_suite mptcp_crypto_suite = {
 66         .name = "mptcp-crypto",
 67         .test_cases = mptcp_crypto_test_cases,
 68 };
 69 
 70 kunit_test_suite(mptcp_crypto_suite);
 71 
 72 MODULE_LICENSE("GPL");
 73 MODULE_DESCRIPTION("KUnit tests for MPTCP Crypto");
 74 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php