linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 02/15] unit/test-crypto: Add test for bt_crypto_gatt_hash
Date: Tue, 29 Jan 2019 15:26:21 +0200	[thread overview]
Message-ID: <20190129132634.28786-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20190129132634.28786-1-luiz.dentz@gmail.com>

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

This adds test case base on the example given in the spec.
---
 unit/test-crypto.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/unit/test-crypto.c b/unit/test-crypto.c
index bc37abb51..5a938c09e 100644
--- a/unit/test-crypto.c
+++ b/unit/test-crypto.c
@@ -208,6 +208,54 @@ static void test_sign(gconstpointer data)
 	tester_test_passed();
 }
 
+static void test_gatt_hash(gconstpointer data)
+{
+	struct iovec iov;
+	const uint8_t m[] = {
+			0x01, 0x00, 0x00, 0x28, 0x00, 0x18, 0x02, 0x00,
+			0x03, 0x28, 0x0A, 0x03, 0x00, 0x00, 0x2A, 0x04,
+			0x00, 0x03, 0x28, 0x02, 0x05, 0x00, 0x01, 0x2A,
+			0x06, 0x00, 0x00, 0x28, 0x01, 0x18, 0x07, 0x00,
+			0x03, 0x28, 0x20, 0x08, 0x00, 0x05, 0x2A, 0x09,
+			0x00, 0x02, 0x29, 0x0A, 0x00, 0x03, 0x28, 0x02,
+			0x0B, 0x00, 0xFF, 0xFF, 0x0C, 0x00, 0x03, 0x28,
+			0x02, 0x0D, 0x00, 0xFF, 0xFF, 0x0E, 0x00, 0x00,
+			0x28, 0x08, 0x18, 0x0F, 0x00, 0x02, 0x28, 0x14,
+			0x00, 0x16, 0x00, 0x0F, 0x18, 0x10, 0x00, 0x03,
+			0x28, 0xA2, 0x11, 0x00, 0x18, 0x2A, 0x12, 0x00,
+			0x02, 0x29, 0x13, 0x00, 0x00, 0x29, 0x00, 0x00,
+			0x14, 0x00, 0x01, 0x28, 0x0F, 0x18, 0x15, 0x00,
+			0x03, 0x28, 0x02, 0x16, 0x00, 0x19, 0x2A };
+	const uint8_t exp[16] = {
+			0x22, 0x7C, 0xE3, 0x34, 0x22, 0xBA, 0xA5, 0xDD,
+			0x6F, 0xA0, 0x82, 0x2A, 0xC1, 0xAD, 0x94, 0x19 };
+	uint8_t res[16];
+
+	tester_debug("M:");
+	util_hexdump(' ', m, sizeof(m), print_debug, NULL);
+
+	iov.iov_base = (void *) m;
+	iov.iov_len = sizeof(m);
+
+	if (!bt_crypto_gatt_hash(crypto, &iov, 1, 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();
+}
+
 int main(int argc, char *argv[])
 {
 	int exit_status;
@@ -226,6 +274,8 @@ int main(int argc, char *argv[])
 	tester_add("/crypto/sign_att_4", &test_data_4, NULL, test_sign, NULL);
 	tester_add("/crypto/sign_att_5", &test_data_5, NULL, test_sign, NULL);
 
+	tester_add("/crypto/gatt_hash", NULL, NULL, test_gatt_hash, NULL);
+
 	exit_status = tester_run();
 
 	bt_crypto_unref(crypto);
-- 
2.17.2


  reply	other threads:[~2019-01-29 13:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29 13:26 [PATCH BlueZ 01/15] shared/crypto: Add bt_crypto_gatt_hash Luiz Augusto von Dentz
2019-01-29 13:26 ` Luiz Augusto von Dentz [this message]
2019-01-29 13:26 ` [PATCH BlueZ 03/15] lib/uuid: Introduce definition for GATT caching attributes Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 04/15] shared/util: Add decoding support " Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 05/15] shared/att-types: Add errors introduced by GATT caching Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 06/15] monitor: Decode GATT Caching errors Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 07/15] shared/gatt-db: Introduce Database Hash Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 08/15] shared/gatt-db: Generate database hash Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 09/15] gatt: Add caching support for server Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 10/15] shared/gatt-db: Add gatt_db_set_authorize Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 11/15] shared/gatt-server: Add bt_gatt_server_set_authorize Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 12/15] gatt: Implement Robust Caching handling for server Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 13/15] shared/gatt-client: Read database hash if available Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 14/15] shared/gatt-client: Write Client Features Luiz Augusto von Dentz
2019-01-29 13:26 ` [PATCH BlueZ 15/15] device: Store Database Hash on storage Luiz Augusto von Dentz
2019-02-06 11:49 ` [PATCH BlueZ 01/15] shared/crypto: Add bt_crypto_gatt_hash Luiz Augusto von Dentz

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=20190129132634.28786-2-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;
as well as URLs for NNTP newsgroup(s).