Debian Codegraph @

net/mptcp/crypto.c

raw
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é <[email protected]>
9 * Christoph Paasch <[email protected]>
10 * Jaakko Korkeaniemi <[email protected]>
11 * Gregory Detal <[email protected]>
12 * Fabien Duchêne <[email protected]>
13 * Andreas Seelinger <[email protected]>
14 * Lavkesh Lahngir <[email protected]>
15 * Andreas Ripke <[email protected]>
16 * Vlad Dogaru <[email protected]>
17 * Octavian Purdila <[email protected]>
18 * John Ronan <[email protected]>
19 * Catalin Nicutar <[email protected]>
20 * Brandon Heller <[email protected]>
21 */
22
23 #include <linux/kernel.h>
24 #include <crypto/sha2.h>
25
26 #include "protocol.h"
27
28 #define SHA256_DIGEST_WORDS (SHA256_DIGEST_SIZE / 4)
29
30 void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn)
31 {
32 __be32 mptcp_hashed_key[SHA256_DIGEST_WORDS];
33 __be64 input = cpu_to_be64(key);
34
35 sha256((__force u8 *)&input, sizeof(input), (u8 *)mptcp_hashed_key);
36
37 if (token)
38 *token = be32_to_cpu(mptcp_hashed_key[0]);
39 if (idsn)
40 *idsn = be64_to_cpu(*((__be64 *)&mptcp_hashed_key[6]));
41 }
42
43 void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac)
44 {
45 __be64 key[2] = { cpu_to_be64(key1), cpu_to_be64(key2) };
46
47 hmac_sha256_usingrawkey((const u8 *)key, sizeof(key), msg, len, hmac);
48 }
49
50 #if IS_MODULE(CONFIG_MPTCP_KUNIT_TEST)
51 EXPORT_SYMBOL_GPL(mptcp_crypto_hmac_sha);
52 #endif