From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC v2 01/12] shared/crypto: Add bt_crypto_sirk
Date: Tue, 7 Mar 2023 14:24:11 -0800 [thread overview]
Message-ID: <20230307222422.2608483-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds bt_crypto_sirk which attempts to generate a unique SIRK using
the following steps:
- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.
---
src/shared/crypto.c | 40 ++++++++++++++++++++++++++++++++++++++++
src/shared/crypto.h | 3 +++
2 files changed, 43 insertions(+)
diff --git a/src/shared/crypto.c b/src/shared/crypto.c
index 4cb2ea857ea8..5449621b55ea 100644
--- a/src/shared/crypto.c
+++ b/src/shared/crypto.c
@@ -926,3 +926,43 @@ bool bt_crypto_sef(struct bt_crypto *crypto, const uint8_t k[16],
return true;
}
+
+/* Generates a SIRK from a string using the following steps:
+ * - Generate a hash (k) using the str as input
+ * - Generate a hash (sirk) using vendor, product, version and source as input
+ * - Encrypt sirk using k as LTK with sef function.
+ */
+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])
+{
+ struct iovec iov[4];
+ uint8_t k[16];
+ uint8_t sirk_plaintext[16];
+
+ if (!crypto)
+ return false;
+
+ iov[0].iov_base = (void *)str;
+ iov[0].iov_len = strlen(str);
+
+ /* Generate a k using the str as input */
+ if (!bt_crypto_gatt_hash(crypto, iov, 1, k))
+ return false;
+
+ iov[0].iov_base = &vendor;
+ iov[0].iov_len = sizeof(vendor);
+ iov[1].iov_base = &product;
+ iov[1].iov_len = sizeof(product);
+ iov[2].iov_base = &version;
+ iov[2].iov_len = sizeof(version);
+ iov[3].iov_base = &source;
+ iov[3].iov_len = sizeof(source);
+
+ /* Generate a sirk using vendor, product, version and source as input */
+ if (!bt_crypto_gatt_hash(crypto, iov, 4, sirk_plaintext))
+ return false;
+
+ /* Encrypt sirk using k as LTK with sef function */
+ return bt_crypto_sef(crypto, k, sirk_plaintext, sirk);
+}
diff --git a/src/shared/crypto.h b/src/shared/crypto.h
index fc1ba0c4feeb..d45308abf90a 100644
--- a/src/shared/crypto.h
+++ b/src/shared/crypto.h
@@ -57,3 +57,6 @@ bool bt_crypto_sef(struct bt_crypto *crypto, const uint8_t k[16],
const uint8_t sirk[16], uint8_t out[16]);
bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16],
const uint8_t r[3], uint8_t hash[3]);
+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]);
--
2.39.2
next reply other threads:[~2023-03-07 22:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 22:24 Luiz Augusto von Dentz [this message]
2023-03-07 22:24 ` [RFC v2 02/12] shared/ad: Add RSI data type Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 03/12] doc: Add set-api Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 04/12] device-api: Add Set property Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 05/12] core: Add initial implementation of DeviceSet interface Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 06/12] core: Check if device has RSI Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 07/12] main.conf: Add CSIP profile configurable options Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 08/12] shared/csip: Add initial code for handling CSIP Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 09/12] profiles: Add initial code for csip plugin Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 10/12] tools: Add support to generate RSI using SIRK Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 11/12] client: Add support for DeviceSet proxy Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 12/12] client: Use AdvertisingFlags when available Luiz Augusto von Dentz
2023-03-08 2:12 ` [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk bluez.test.bot
2023-03-11 0:40 ` [RFC v2 01/12] " patchwork-bot+bluetooth
2023-03-13 5:36 ` Luiz Augusto von Dentz
2023-03-13 23:29 ` Pauli Virtanen
2023-03-14 0:18 ` Luiz Augusto von Dentz
2023-03-14 0:57 ` Pauli Virtanen
2023-04-06 0:16 ` Luiz Augusto von Dentz
2023-04-06 18:08 ` Pauli Virtanen
2023-04-06 20:14 ` Luiz Augusto von Dentz
2023-04-13 18:48 ` Luiz Augusto von Dentz
2023-04-13 21:14 ` Pauli Virtanen
2023-04-14 21:56 ` Luiz Augusto von Dentz
2023-04-15 14:57 ` Pauli Virtanen
2023-04-13 20:11 ` Pauli Virtanen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230307222422.2608483-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox