All of lore.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 4/5] test-crypto: Add /crypto/sef test
Date: Thu, 22 Dec 2022 14:43:28 -0800	[thread overview]
Message-ID: <20221222224329.685837-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20221222224329.685837-1-luiz.dentz@gmail.com>

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

This adds test /crypto/sef which validas the implementation of
bt_crypto_sef using the sample data from CSIS[1] spec:

 A.2. sef SIRK Encryption Function

> unit/test-crypto -s "/crypto/sef"
  SIRK:
    cd cc 72 dd 86 8c cd ce 22 fd a1 21 09 7d 7d 45  ..r....."..!.}}E
  K:
    d9 ce e5 3c 22 c6 1e 06 6f 69 48 d4 9b 1b 6e 67  ...<"...oiH...ng
  Expected:
    46 d3 5f f2 d5 62 25 7e a0 24 35 e1 35 38 0a 17  F._..b%~.$5.58..
  Result:
    46 d3 5f f2 d5 62 25 7e a0 24 35 e1 35 38 0a 17  F._..b%~.$5.58..

[1]https://www.bluetooth.com/specifications/csis-1-0-1/
---
 unit/test-crypto.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/unit/test-crypto.c b/unit/test-crypto.c
index b5404d542af3..8fd7bec8ea83 100644
--- a/unit/test-crypto.c
+++ b/unit/test-crypto.c
@@ -311,6 +311,44 @@ static void test_verify_sign(gconstpointer data)
 	tester_test_passed();
 }
 
+static void test_sef(const void *data)
+{
+	const uint8_t sirk[16] = {
+			0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce,
+			0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 };
+	const uint8_t k[16] = {
+			0xd9, 0xce, 0xe5, 0x3c, 0x22, 0xc6, 0x1e, 0x06,
+			0x6f, 0x69, 0x48, 0xd4, 0x9b, 0x1b, 0x6e, 0x67 };
+	const uint8_t exp[16] = {
+			0x46, 0xd3, 0x5f, 0xf2, 0xd5, 0x62, 0x25, 0x7e,
+			0xa0, 0x24, 0x35, 0xe1, 0x35, 0x38, 0x0a, 0x17 };
+	uint8_t res[16];
+
+	tester_debug("SIRK:");
+	util_hexdump(' ', sirk, 16, print_debug, NULL);
+
+	tester_debug("K:");
+	util_hexdump(' ', k, 16, print_debug, NULL);
+
+	if (!bt_crypto_sef(crypto, k, sirk, res)) {
+		tester_test_failed();
+		return;
+	}
+
+	tester_debug("Expected:");
+	util_hexdump(' ', exp, 16, print_debug, NULL);
+
+	tester_debug("Result:");
+	util_hexdump(' ', res, 16, print_debug, NULL);
+
+	if (memcmp(res, exp, 16)) {
+		tester_test_failed();
+		return;
+	}
+
+	tester_test_passed();
+}
+
 static void test_sih(const void *data)
 {
 	const uint8_t k[16] = {
@@ -371,6 +409,7 @@ int main(int argc, char *argv[])
 						NULL, test_verify_sign, NULL);
 	tester_add("/crypto/verify_sign_too_short", &verify_sign_too_short_data,
 						NULL, test_verify_sign, NULL);
+	tester_add("/crypto/sef", NULL, NULL, test_sef, NULL);
 	tester_add("/crypto/sih", NULL, NULL, test_sih, NULL);
 
 	exit_status = tester_run();
-- 
2.37.3


  parent reply	other threads:[~2022-12-22 22:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 22:43 [PATCH BlueZ 1/5] shared/crypto: Adds bt_crypto_sih Luiz Augusto von Dentz
2022-12-22 22:43 ` [PATCH BlueZ 2/5] test-crypto: Add /crypto/sih test Luiz Augusto von Dentz
2022-12-22 22:43 ` [PATCH BlueZ 3/5] shared/crypto: Adds bt_crypto_sef Luiz Augusto von Dentz
2022-12-22 22:43 ` Luiz Augusto von Dentz [this message]
2022-12-22 22:43 ` [PATCH BlueZ 5/5] monitor: Add support for decoding RSI Luiz Augusto von Dentz
2022-12-23  1:24 ` [BlueZ,1/5] shared/crypto: Adds bt_crypto_sih bluez.test.bot
2023-01-03 22:20 ` [PATCH BlueZ 1/5] " 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=20221222224329.685837-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.