crypto.c (0f69403d2535ffc7200a8414cf3ca66a49b0d741) | crypto.c (a00a582203dbc43ea311a50e979038fc0c8ee19f) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* Multipath TCP cryptographic functions 3 * Copyright (c) 2017 - 2019, Intel Corporation. 4 * 5 * Note: This code is based on mptcp_ctrl.c, mptcp_ipv4.c, and 6 * mptcp_ipv6 from multipath-tcp.org, authored by: 7 * 8 * Sébastien Barré <sebastien.barre@uclouvain.be> --- 73 unchanged lines hidden (view full) --- 82 for (i = 0; i < 8; i++) 83 input[i + 8] ^= key2be[i]; 84 85 sha256_init(&state); 86 sha256_update(&state, input, SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE); 87 sha256_final(&state, (u8 *)hmac); 88} 89 | 1// SPDX-License-Identifier: GPL-2.0 2/* Multipath TCP cryptographic functions 3 * Copyright (c) 2017 - 2019, Intel Corporation. 4 * 5 * Note: This code is based on mptcp_ctrl.c, mptcp_ipv4.c, and 6 * mptcp_ipv6 from multipath-tcp.org, authored by: 7 * 8 * Sébastien Barré <sebastien.barre@uclouvain.be> --- 73 unchanged lines hidden (view full) --- 82 for (i = 0; i < 8; i++) 83 input[i + 8] ^= key2be[i]; 84 85 sha256_init(&state); 86 sha256_update(&state, input, SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE); 87 sha256_final(&state, (u8 *)hmac); 88} 89 |
90#ifdef CONFIG_MPTCP_HMAC_TEST 91struct test_cast { 92 char *key; 93 char *msg; 94 char *result; 95}; 96 97/* we can't reuse RFC 4231 test vectors, as we have constraint on the 98 * input and key size. 99 */ 100static struct test_cast tests[] = { 101 { 102 .key = "0b0b0b0b0b0b0b0b", 103 .msg = "48692054", 104 .result = "8385e24fb4235ac37556b6b886db106284a1da671699f46db1f235ec622dcafa", 105 }, 106 { 107 .key = "aaaaaaaaaaaaaaaa", 108 .msg = "dddddddd", 109 .result = "2c5e219164ff1dca1c4a92318d847bb6b9d44492984e1eb71aff9022f71046e9", 110 }, 111 { 112 .key = "0102030405060708", 113 .msg = "cdcdcdcd", 114 .result = "e73b9ba9969969cefb04aa0d6df18ec2fcc075b6f23b4d8c4da736a5dbbc6e7d", 115 }, 116}; 117 118static int __init test_mptcp_crypto(void) 119{ 120 char hmac[32], hmac_hex[65]; 121 u32 nonce1, nonce2; 122 u64 key1, key2; 123 u8 msg[8]; 124 int i, j; 125 126 for (i = 0; i < ARRAY_SIZE(tests); ++i) { 127 /* mptcp hmap will convert to be before computing the hmac */ 128 key1 = be64_to_cpu(*((__be64 *)&tests[i].key[0])); 129 key2 = be64_to_cpu(*((__be64 *)&tests[i].key[8])); 130 nonce1 = be32_to_cpu(*((__be32 *)&tests[i].msg[0])); 131 nonce2 = be32_to_cpu(*((__be32 *)&tests[i].msg[4])); 132 133 put_unaligned_be32(nonce1, &msg[0]); 134 put_unaligned_be32(nonce2, &msg[4]); 135 136 mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac); 137 for (j = 0; j < 32; ++j) 138 sprintf(&hmac_hex[j << 1], "%02x", hmac[j] & 0xff); 139 hmac_hex[64] = 0; 140 141 if (memcmp(hmac_hex, tests[i].result, 64)) 142 pr_err("test %d failed, got %s expected %s", i, 143 hmac_hex, tests[i].result); 144 else 145 pr_info("test %d [ ok ]", i); 146 } 147 return 0; 148} 149 150late_initcall(test_mptcp_crypto); | 90#if IS_MODULE(CONFIG_MPTCP_KUNIT_TESTS) 91EXPORT_SYMBOL_GPL(mptcp_crypto_hmac_sha); |
151#endif | 92#endif |