From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 3/3] tester: Add HCI LE Encrypt command test
Date: Wed, 13 May 2015 15:09:02 +0300 [thread overview]
Message-ID: <1431518942-24753-3-git-send-email-Andrei.Emeltchenko.news@gmail.com> (raw)
In-Reply-To: <1431518942-24753-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Use RFC 4493 "The AES-CMAC Algorithm" sample test vectors to test HCI
controller encryption.
---
tools/hci-tester.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/tools/hci-tester.c b/tools/hci-tester.c
index a5dbde2..903921d 100644
--- a/tools/hci-tester.c
+++ b/tools/hci-tester.c
@@ -45,6 +45,19 @@ struct user_data {
uint16_t handle_ut;
};
+static void swap_buf(const uint8_t *src, uint8_t *dst, uint16_t len)
+{
+ int i;
+
+ for (i = 0; i < len; i++)
+ dst[len - 1 - i] = src[i];
+}
+
+static void test_debug(const char *str, void *user_data)
+{
+ tester_debug("%s", str);
+}
+
static void test_pre_setup_lt_address(const void *data, uint8_t size,
void *user_data)
{
@@ -339,6 +352,60 @@ static void test_le_clear_white_list(const void *test_data)
test_command(BT_HCI_CMD_LE_CLEAR_WHITE_LIST);
}
+static void test_le_encrypt_complete(const void *data, uint8_t size,
+ void *user_data)
+{
+ const struct bt_hci_rsp_le_encrypt *rsp = data;
+ uint8_t sample[16] = {
+ 0x7d, 0xf7, 0x6b, 0x0c, 0x1a, 0xb8, 0x99, 0xb3,
+ 0x3e, 0x42, 0xf0, 0x47, 0xb9, 0x1b, 0x54, 0x6f
+ };
+ uint8_t enc_data[16];
+
+ if (rsp->status) {
+ tester_warn("Failed HCI LE Encrypt (0x%02x)", rsp->status);
+ tester_test_failed();
+ return;
+ }
+
+ swap_buf(rsp->data, enc_data, 16);
+ util_hexdump('>', enc_data, 16, test_debug, NULL);
+
+ if (!memcmp(sample, enc_data, 16))
+ tester_test_passed();
+ else
+ tester_test_failed();
+}
+
+/* Data are taken from RFC 4493 Test Vectors */
+static void test_le_encrypt(const void *test_data)
+{
+ struct user_data *user = tester_get_data();
+ struct bt_hci_cmd_le_encrypt cmd;
+ uint8_t key[16] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
+ };
+ uint8_t plaintext[16] = { 0 };
+
+ /* Swap bytes since our interface has LE interface, opposed to
+ * common crypto interface
+ */
+ swap_buf(key, cmd.key, 16);
+ swap_buf(plaintext, cmd.plaintext, 16);
+
+ util_hexdump('<', cmd.key, 16, test_debug, NULL);
+ util_hexdump('<', cmd.plaintext, 16, test_debug, NULL);
+
+ if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_LE_ENCRYPT, &cmd, sizeof(cmd),
+ test_le_encrypt_complete, NULL, NULL)) {
+ tester_warn("Failed to send HCI LE Encrypt command");
+ tester_test_failed();
+ return;
+ }
+
+}
+
static void test_inquiry_complete(const void *data, uint8_t size,
void *user_data)
{
@@ -657,6 +724,8 @@ int main(int argc, char *argv[])
test_le_read_white_list_size);
test_hci_local("LE Clear White List", NULL, NULL,
test_le_clear_white_list);
+ test_hci_local("LE Encrypt", NULL, NULL,
+ test_le_encrypt);
test_hci_local("Inquiry (LIAC)", NULL, NULL, test_inquiry_liac);
--
2.1.4
next prev parent reply other threads:[~2015-05-13 12:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 12:09 [PATCH 1/3] btdev: Add LE Encrypt command support to emulator Andrei Emeltchenko
2015-05-13 12:09 ` [PATCH 2/3] btdev: Refactor Le Rand using Linux crypto infrastructure Andrei Emeltchenko
2015-05-13 12:09 ` Andrei Emeltchenko [this message]
2015-05-14 15:13 ` [PATCH 1/3] btdev: Add LE Encrypt command support to emulator Szymon Janc
2015-05-17 7:13 ` Johan Hedberg
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=1431518942-24753-3-git-send-email-Andrei.Emeltchenko.news@gmail.com \
--to=andrei.emeltchenko.news@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