summaryrefslogtreecommitdiff
path: root/unit
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-12-20 14:55:59 -0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-12-21 16:31:06 -0800
commit09293fd22b3edb825a268fbf28480f4e3a53a1e9 (patch)
treec051d99a361ec95748e15111149c421b23234a3a /unit
parent5abd9914a1eb23e7d2b985516453f1fe7559c79f (diff)
downloadbluez-09293fd22b3edb825a268fbf28480f4e3a53a1e9.tar.gz
test-crypto: Add /crypto/sih test
This adds test /crypto/sih which validas the implementation of bt_crypto_sih using the sample data from CSIS[1] spec: A.1. sih Resolvable Set Identifier hash function > unit/test-crypto -s "/crypto/sih" K: cd cc 72 dd 86 8c cd ce 22 fd a1 21 09 7d 7d 45 ..r....."..!.}}E R: 63 f5 69 c.i Expected: da 48 19 .H. Result: da 48 19 .H. [1] https://www.bluetooth.com/specifications/csis-1-0-1/
Diffstat (limited to 'unit')
-rw-r--r--unit/test-crypto.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/unit/test-crypto.c b/unit/test-crypto.c
index 3a88b4a52..b5404d542 100644
--- a/unit/test-crypto.c
+++ b/unit/test-crypto.c
@@ -311,6 +311,40 @@ static void test_verify_sign(gconstpointer data)
tester_test_passed();
}
+static void test_sih(const void *data)
+{
+ const uint8_t k[16] = {
+ 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce,
+ 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 };
+ const uint8_t r[3] = { 0x63, 0xf5, 0x69 };
+ const uint8_t exp[3] = { 0xda, 0x48, 0x19 };
+ uint8_t hash[3];
+
+ tester_debug("K:");
+ util_hexdump(' ', k, 16, print_debug, NULL);
+
+ tester_debug("R:");
+ util_hexdump(' ', r, 3, print_debug, NULL);
+
+ if (!bt_crypto_sih(crypto, k, r, hash)) {
+ tester_test_failed();
+ return;
+ }
+
+ tester_debug("Expected:");
+ util_hexdump(' ', exp, 3, print_debug, NULL);
+
+ tester_debug("Result:");
+ util_hexdump(' ', hash, 3, print_debug, NULL);
+
+ if (memcmp(hash, exp, 3)) {
+ tester_test_failed();
+ return;
+ }
+
+ tester_test_passed();
+}
+
int main(int argc, char *argv[])
{
int exit_status;
@@ -337,6 +371,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/sih", NULL, NULL, test_sih, NULL);
exit_status = tester_run();