unit/test-crypto: Add test for bt_crypto_gatt_hash
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 5 Mar 2018 14:36:55 +0000 (16:36 +0200)
committerhimanshu <h.himanshu@samsung.com>
Wed, 22 Jan 2020 13:48:40 +0000 (19:18 +0530)
This adds test case base on the example given in the spec.

Change-Id: Ibc713afd03926375087c248a4fe9882784ea95a7
Signed-off-by: himanshu <h.himanshu@samsung.com>
unit/test-crypto.c

index bc37abb..e20b2fa 100755 (executable)
@@ -208,6 +208,70 @@ static void test_sign(gconstpointer data)
        tester_test_passed();
 }
 
+static void test_gatt_hash(gconstpointer data)
+{
+       struct iovec iov[7];
+       const uint8_t m[7][16] = {
+               /* M0 */
+               { 0x01, 0x00, 0x00, 0x28, 0x00, 0x18, 0x02, 0x00,
+               0x03, 0x28, 0x0A, 0x03, 0x00, 0x00, 0x2A, 0x04 },
+               /* M1 */
+               { 0x00, 0x03, 0x28, 0x02, 0x05, 0x00, 0x01, 0x2A,
+               0x06, 0x00, 0x00, 0x28, 0x01, 0x18, 0x07, 0x00 },
+               /* M2 */
+               { 0x03, 0x28, 0x20, 0x08, 0x00, 0x05, 0x2A, 0x09,
+               0x00, 0x02, 0x29, 0x0A, 0x00, 0x03, 0x28, 0x0A },
+               /* M3 */
+               { 0x0B, 0x00, 0x29, 0x2B, 0x0C, 0x00, 0x03, 0x28,
+               0x02, 0x0D, 0x00, 0x2A, 0x2B, 0x0E, 0x00, 0x00 },
+               /* M4 */
+               { 0x28, 0x08, 0x18, 0x0F, 0x00, 0x02, 0x28, 0x14,
+               0x00, 0x16, 0x00, 0x0F, 0x18, 0x10, 0x00, 0x03 },
+               /* M5 */
+               { 0x28, 0xA2, 0x11, 0x00, 0x18, 0x2A, 0x12, 0x00,
+               0x02, 0x29, 0x13, 0x00, 0x00, 0x29, 0x00, 0x00 },
+               /* M6 */
+               { 0x14, 0x00, 0x01, 0x28, 0x0F, 0x18, 0x15, 0x00,
+               0x03, 0x28, 0x02, 0x16, 0x00, 0x19, 0x2A }
+       };
+       const uint8_t exp[16] = {
+               0xF1, 0xCA, 0x2D, 0x48, 0xEC, 0xF5, 0x8B, 0xAC,
+               0x8A, 0x88, 0x30, 0xBB, 0xB9, 0xFB, 0xA9, 0x90
+       };
+       uint8_t res[16];
+       int i;
+
+       for (i = 0; i < 7; i++) {
+               int len = sizeof(m[i]);
+
+               if (i == 6)
+                       len -= 1;
+
+               tester_debug("M%u:", i);
+               util_hexdump(' ', m[i], len, print_debug, NULL);
+               iov[i].iov_base = (void *) m[i];
+               iov[i].iov_len = len;
+       }
+
+       if (!bt_crypto_gatt_hash(crypto, iov, 7, 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 +290,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);