[PATCH BlueZ 02/15] unit/test-crypto: Add test for bt_crypto_gatt_hash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux