// SPDX-License-Identifier: GPL-2.01/* Multipath TCP cryptographic functions2* Copyright (c) 2017 - 2019, Intel Corporation.3*4* Note: This code is based on mptcp_ctrl.c, mptcp_ipv4.c, and5* mptcp_ipv6 from multipath-tcp.org, authored by:6*7* Sébastien Barré <[email protected]>8* Christoph Paasch <[email protected]>9* Jaakko Korkeaniemi <[email protected]>10* Gregory Detal <[email protected]>11* Fabien Duchêne <[email protected]>12* Andreas Seelinger <[email protected]>13* Lavkesh Lahngir <[email protected]>14* Andreas Ripke <[email protected]>15* Vlad Dogaru <[email protected]>16* Octavian Purdila <[email protected]>17* John Ronan <[email protected]>18* Catalin Nicutar <[email protected]>19* Brandon Heller <[email protected]>20*/2122#include <linux/kernel.h>23#include <crypto/sha2.h>2425#include "protocol.h"2627#define SHA256_DIGEST_WORDS (SHA256_DIGEST_SIZE / 4)2829void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn)30{31__be32 mptcp_hashed_key[SHA256_DIGEST_WORDS];32__be64 input = cpu_to_be64(key);3334sha256((__force u8 *)&input, sizeof(input), (u8 *)mptcp_hashed_key);3536if (token)37*token = be32_to_cpu(mptcp_hashed_key[0]);38if (idsn)39*idsn = be64_to_cpu(*((__be64 *)&mptcp_hashed_key[6]));40}4142void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac)43{44__be64 key[2] = { cpu_to_be64(key1), cpu_to_be64(key2) };4546hmac_sha256_usingrawkey((const u8 *)key, sizeof(key), msg, len, hmac);47}4849#if IS_MODULE(CONFIG_MPTCP_KUNIT_TEST)50EXPORT_SYMBOL_GPL(mptcp_crypto_hmac_sha);51#endif525354