summaryrefslogtreecommitdiff
path: root/unit
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2018-03-05 16:36:55 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2019-02-06 13:12:00 +0200
commit810d8ff34fd2158018b2e021403cd1f33a790702 (patch)
tree39f96294f64e091e7694c0debc662fcbf4644a71 /unit
parent8474ad9fdbdefd3627e92e8daffa2dfacbaf19cd (diff)
downloadbluez-810d8ff34fd2158018b2e021403cd1f33a790702.tar.gz
unit/test-crypto: Add test for bt_crypto_gatt_hash
This adds test case base on the example given in the spec.
Diffstat (limited to 'unit')
-rw-r--r--unit/test-crypto.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/unit/test-crypto.c b/unit/test-crypto.c
index bc37abb51..e20b2fa66 100644
--- a/unit/test-crypto.c
+++ b/unit/test-crypto.c
@@ -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);