Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp768794rwj; Thu, 22 Dec 2022 14:47:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXvW+NLghc1g2lUAOvw6+/EAsC0nLTdzJhPxW8UZiTYEwjjzB4kw8B5UcSMJOyH2QFRFZ66N X-Received: by 2002:a17:907:9a98:b0:7c1:d4c:f08c with SMTP id km24-20020a1709079a9800b007c10d4cf08cmr5591825ejc.4.1671749260564; Thu, 22 Dec 2022 14:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671749260; cv=none; d=google.com; s=arc-20160816; b=DqeJSQzab7r75Pvd7o4Rb0mwgHy3XFBC0r0DvRjPGN0A24G1b+iLKye5AcEgtuRFDw zqaVz73m2UEIS97OtKwdGI9QtQBMMAs0beBP/UY14gjHb+lQ4hpRVi2GJAncAX4ES4sc KgDtd/SQd+J27krJG5yUYTCz2znDv5KNbAUblxPoyCAU8b3FdPlQjP90F6/KdcCdwtpL hebQLwwIJ24wMM/oDFoMf7+NVDeffiuQjctUoph/gb22BJKfQD5ZZ94PcaD7j17/2W6G 9QQvdrJcmpIqpk/8hX+qUWeE0g5hkxQ2a3IABMYDUlweM/2UNU3BiyzZ/zVy1aA5Km3r lebQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=FREv2B+vzQnAcYjD62du1FNguIros7B8DOElyGaLYug=; b=oz1wxvHmLgVFAWiLO90ZbEDpUL56FoeMk77MoAnk1zxBHM+RjiACxnHEruUqJyBP6T FZy5AM0k9hKgosfDpQTdTRQUkjM3q/B+muoIY7kYQfVA76LFBdASRzIFchCV+FRHioc1 uUz/4QQEKJ9YTKu38Vf5Z3thm8a2UAPTmjEzJ3GQIZdWPyCXRVyC71/F7QFOZ7GCJjLm aPUtwzdaiAXYQvRZLB9X1/omgQpTd4jOnz8YowVDkYobAMRX0yhTzPLfv9qLwbDo3Brf AzmH5qzObIsS02BifmJirrBzIf1qB0uALSc+jK+uLJ8LN0hrAtDkusZ7arPFULxo3i2j 6FAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JdBHurts; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw18-20020a170906479200b0078d93325645si1434891ejc.405.2022.12.22.14.46.59; Thu, 22 Dec 2022 14:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JdBHurts; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229475AbiLVWng (ORCPT + 99 others); Thu, 22 Dec 2022 17:43:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbiLVWne (ORCPT ); Thu, 22 Dec 2022 17:43:34 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C64F0EBE for ; Thu, 22 Dec 2022 14:43:32 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id f9so2229589pgf.7 for ; Thu, 22 Dec 2022 14:43:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=FREv2B+vzQnAcYjD62du1FNguIros7B8DOElyGaLYug=; b=JdBHurtsexgb6mf1WSLcvnWmwstFW1R/w1s29adGbYHnS3+xRw+NOLwBiXNW7kbZk+ pFtNlEGf658K2H9uBGp/LWoOCEZ9W7uN00vJETpTCsn0xurUS9JAlrlafkiAWnHW/srf TbsIx5HSB3883cOsqMM1LeigZvLG5j1aCY3oBbCLqyWwNq6fZZpnUll2u7EbWxS4xQI3 yzvstNMTDw4liq4MeoZcepyyDfr+DeUaYfVvP89a9ONDdpB3hhogenQp+wuFL8o2tAFE Vu2aP2S1r0OgMo4TcsA+UpB0jdDHCpBBGm9Glvh612LnaqrO+gwoQDhIHiSzFNT8INAb AYFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FREv2B+vzQnAcYjD62du1FNguIros7B8DOElyGaLYug=; b=LYd0AqCGnJ+n37AiCJ2SJDn9fkqt4hrKYhnIPPO3hduoIaeOr/8Y0P8l0h5eH0RSnd eC+V9r0x/Aj1pXTCwL17DYR5E9XOa8gmluHDGYSp/tO+NRdNUNc4HfFY2DyGRP88JGrW zDomdHssT7+vbflbtibnMl3Y0rJkpB36DHqecVBtUViH7idYLGAifMQ/nji7VH1XnECJ 0qvUivf4qt4Or8S853du1i2V6gfq28IPJmpI+e1A5EjxJ/BALc+gzXgnGpphN9E2IgXq 3Q9GLmN2QLaZwT8mQql+BKlaOXlAxOmyr9+cHMgMPvjpyMZfmyNh6PknGUEcRy61f2Bp 023Q== X-Gm-Message-State: AFqh2kr77qnqiO/qzDT2qMMTiaxhzPvxPdey+DJQrenQvVcGQ0QrwT8Q fqJ94joqshqNRhTsjME+MYKnKLXeYFUExQ== X-Received: by 2002:a05:6a00:a07:b0:580:9431:1b1a with SMTP id p7-20020a056a000a0700b0058094311b1amr333445pfh.5.1671749011755; Thu, 22 Dec 2022 14:43:31 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id f6-20020aa79d86000000b0056bbeaa82b9sm1187546pfq.113.2022.12.22.14.43.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 14:43:31 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/5] shared/crypto: Adds bt_crypto_sih Date: Thu, 22 Dec 2022 14:43:25 -0800 Message-Id: <20221222224329.685837-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds bt_crypto_sih is is used to create a hash as stated on CSIS[1] spec: '4.7. Resolvable Set Identifier hash function sih' https://www.bluetooth.com/specifications/csis-1-0-1/ --- src/shared/crypto.c | 36 ++++++++++++++++++++++++++++++++++++ src/shared/crypto.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/src/shared/crypto.c b/src/shared/crypto.c index d5efa416dd99..f164ba69d2a5 100644 --- a/src/shared/crypto.c +++ b/src/shared/crypto.c @@ -737,3 +737,39 @@ bool bt_crypto_gatt_hash(struct bt_crypto *crypto, struct iovec *iov, return true; } + +/* + * Resolvable Set Identifier hash function sih + * + * The RSI hash function sih is used to generate a hash value that is used in + * RSIs. + * + * The following variables are the inputs to the RSI hash function sih: + * + * k is 128 bits + * r is 24 bits + * padding is 104 bits, all set to 0 + * + * r is concatenated with padding to generate r', which is used as the 128-bit + * input parameter plaintextData to security function e: + * + * r'=padding||r + * + * The LSO of r becomes the LSO of r', and the MSO of padding becomes the MSO + * of r'. + * + * For example, if the 24-bit value r is 0x3A98B5, then r' is + * 0x000000000000000000000000003A98B5. + * + * The output of the Resolvable Set Identifier function sih is: + * + * sih(k, r)=e(k, r') mod 2^24 + * + * The output of the security function e is truncated to 24 bits by taking the + * least significant 24 bits of the output of e as the result of sih. + */ +bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16], + const uint8_t r[3], uint8_t hash[3]) +{ + return bt_crypto_ah(crypto, k, r, hash); +} diff --git a/src/shared/crypto.h b/src/shared/crypto.h index 356326d75408..fca52e38e5e2 100644 --- a/src/shared/crypto.h +++ b/src/shared/crypto.h @@ -53,3 +53,5 @@ bool bt_crypto_verify_att_sign(struct bt_crypto *crypto, const uint8_t key[16], const uint8_t *pdu, uint16_t pdu_len); bool bt_crypto_gatt_hash(struct bt_crypto *crypto, struct iovec *iov, size_t iov_len, uint8_t res[16]); +bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16], + const uint8_t r[3], uint8_t hash[3]); -- 2.37.3