public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 3/6] advtest: Use bt_crypto_rsi to generate RSI
Date: Thu, 15 Jan 2026 15:54:04 -0500	[thread overview]
Message-ID: <20260115205408.1554101-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260115205408.1554101-1-luiz.dentz@gmail.com>

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

This makes use of bt_crypto_rsi to generate a valid RSI.
---
 tools/advtest.c | 29 ++---------------------------
 1 file changed, 2 insertions(+), 27 deletions(-)

diff --git a/tools/advtest.c b/tools/advtest.c
index 8df6923d2f2e..706b2503b74c 100644
--- a/tools/advtest.c
+++ b/tools/advtest.c
@@ -75,37 +75,13 @@ static size_t hex2bin(const char *hexstr, uint8_t *buf, size_t buflen)
 	return len;
 }
 
-static bool get_random_bytes(void *buf, size_t num_bytes)
-{
-	ssize_t len;
-	int fd;
-
-	fd = open("/dev/urandom", O_RDONLY);
-	if (fd < 0)
-		return false;
-
-	len = read(fd, buf, num_bytes);
-
-	close(fd);
-
-	if (len < 0)
-		return false;
-
-	return true;
-}
-
 static void generate_rsi(char *val)
 {
-	uint8_t sirk[16], hash[3];
+	uint8_t sirk[16];
 	uint8_t  rsi[6] = {0};
 
 	hex2bin(val, sirk, sizeof(sirk));
 
-	get_random_bytes(&rsi[3], 3);
-
-	rsi[5] &= 0x3f; /* Clear 2 msb */
-	rsi[5] |= 0x40; /* Set 2nd msb */
-
 	crypto = bt_crypto_new();
 	if (!crypto) {
 		fprintf(stderr, "Failed to open crypto interface\n");
@@ -113,8 +89,7 @@ static void generate_rsi(char *val)
 		return;
 	}
 
-	bt_crypto_ah(crypto, sirk, rsi + 3, hash);
-	memcpy(rsi, hash, 3);
+	bt_crypto_rsi(crypto, sirk, rsi);
 
 	print_rpa(rsi);
 }
-- 
2.52.0


  parent reply	other threads:[~2026-01-15 20:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-15 20:54 [PATCH BlueZ v2 1/6] shared/crypto: Add bt_crypto_rsi Luiz Augusto von Dentz
2026-01-15 20:54 ` [PATCH BlueZ v2 2/6] advertising: Use bt_crypto_rsi to generate RSI Luiz Augusto von Dentz
2026-01-15 20:54 ` Luiz Augusto von Dentz [this message]
2026-01-15 20:54 ` [PATCH BlueZ v2 4/6] shared/ad: Make bt_ad_has_data return the data Luiz Augusto von Dentz
2026-01-15 20:54 ` [PATCH BlueZ v2 5/6] advertising: Fix not verifying if RSI set is valid Luiz Augusto von Dentz
2026-01-15 20:54 ` [PATCH BlueZ v2 6/6] advtest: Fix displaying RSI as a byte array rather then an address Luiz Augusto von Dentz
2026-01-15 21:48 ` [BlueZ,v2,1/6] shared/crypto: Add bt_crypto_rsi bluez.test.bot
2026-01-15 22:40 ` [PATCH BlueZ v2 1/6] " patchwork-bot+bluetooth

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=20260115205408.1554101-3-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