public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v1 1/6] shared/crypto: Add bt_crypto_rsi
@ 2026-01-14 21:49 Luiz Augusto von Dentz
  2026-01-14 21:49 ` [PATCH BlueZ v1 2/6] advertising: Use bt_crypto_rsi to generate RSI Luiz Augusto von Dentz
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2026-01-14 21:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds bt_cryptor_rsi which can be used to generate a Resolvable Set
Identifier as per CSIS spec:

https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/28085-CSIS-html5/out/en/index-en.html#UUID-4dc0c19a-2900-d43e-6ea5-e651151d3c3e
---
 src/shared/crypto.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/shared/crypto.h |  2 ++
 2 files changed, 41 insertions(+)

diff --git a/src/shared/crypto.c b/src/shared/crypto.c
index 43d7f7c5c4b7..cb9911682c81 100644
--- a/src/shared/crypto.c
+++ b/src/shared/crypto.c
@@ -788,6 +788,45 @@ bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16],
 	return bt_crypto_ah(crypto, k, r, hash);
 }
 
+/*
+ * The hash is generated by using the RSI hash function sih, with the input
+ * parameter k set to the device’s SIRK, and the input parameter r set to
+ * prand:
+ *
+ * hash = sih(SIRK, prand)
+ *
+ * The prand and hash are concatenated to generate the RSI
+ * resolvableSetIdentifier in the following manner:
+ *
+ * resolvableSetIdentifier = hash || prand
+ */
+bool bt_crypto_rsi(struct bt_crypto *crypto, const uint8_t sirk[16],
+					uint8_t rsi[6])
+{
+	uint8_t prand[3];
+	uint8_t hash[3];
+
+	/* The random number prand shall meet the following requirements:
+	 *
+	 * - The two most significant bits (MSBs) of prand shall be equal to 0
+	 * - At least one bit of the random part of prand shall be 0.
+	 * - At least one bit of the random part of prand shall be 1.
+	 */
+	if (!bt_crypto_random_bytes(crypto, prand, 3))
+		return false;
+
+	prand[2] &= 0x3f;
+	prand[2] |= 0x40;
+
+	if (!bt_crypto_sih(crypto, sirk, prand, hash))
+		return false;
+
+	memcpy(rsi, hash, 3);
+	memcpy(rsi + 3, prand, 3);
+
+	return true;
+}
+
 static bool aes_cmac_zero(struct bt_crypto *crypto, const uint8_t *msg,
 					size_t msg_len, uint8_t res[16])
 {
diff --git a/src/shared/crypto.h b/src/shared/crypto.h
index d45308abf90a..d85f807fe468 100644
--- a/src/shared/crypto.h
+++ b/src/shared/crypto.h
@@ -60,3 +60,5 @@ bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16],
 bool bt_crypto_sirk(struct bt_crypto *crypto, const char *str, uint16_t vendor,
 			uint16_t product, uint16_t version, uint16_t source,
 			uint8_t sirk[16]);
+bool bt_crypto_rsi(struct bt_crypto *crypto, const uint8_t sirk[16],
+					uint8_t rsi[6]);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-14 22:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 21:49 [PATCH BlueZ v1 1/6] shared/crypto: Add bt_crypto_rsi Luiz Augusto von Dentz
2026-01-14 21:49 ` [PATCH BlueZ v1 2/6] advertising: Use bt_crypto_rsi to generate RSI Luiz Augusto von Dentz
2026-01-14 21:49 ` [PATCH BlueZ v1 3/6] advtest: " Luiz Augusto von Dentz
2026-01-14 21:49 ` [PATCH BlueZ v1 4/6] shared/ad: Make bt_ad_has_data return the data Luiz Augusto von Dentz
2026-01-14 21:49 ` [PATCH BlueZ v1 5/6] advertising: Fix not verifying if RSI set is valid Luiz Augusto von Dentz
2026-01-14 21:49 ` [PATCH BlueZ v1 6/6] advtest: Fix displaying RSI as a byte array rather then an address Luiz Augusto von Dentz
2026-01-14 22:41 ` [BlueZ,v1,1/6] shared/crypto: Add bt_crypto_rsi bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox