shared/crypto: Add bt_crypto_gatt_hash
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 5 Mar 2018 09:30:43 +0000 (11:30 +0200)
committerhimanshu <h.himanshu@samsung.com>
Wed, 22 Jan 2020 13:47:59 +0000 (19:17 +0530)
The bt_crypto_gatt_hash uses AES-CCM to create a hash with the contents
stored in the iovec.

Note: The spec disregards the byte order so both the key, msg and res
are not swapped.

Change-Id: Ifaa2b5ce256c17344b6a78b5f056ad5b1d63e1d7
Signed-off-by: himanshu <h.himanshu@samsung.com>
src/shared/crypto.c
src/shared/crypto.h

index a0a5c45..0462de7 100755 (executable)
@@ -692,3 +692,34 @@ bool bt_crypto_h6(struct bt_crypto *crypto, const uint8_t w[16],
 
        return true;
 }
+
+bool bt_crypto_gatt_hash(struct bt_crypto *crypto, struct iovec *iov,
+                               size_t iov_len, uint8_t res[16])
+{
+       const uint8_t key[16] = {};
+       ssize_t len;
+       int fd;
+
+       if (!crypto)
+               return false;
+
+       fd = alg_new(crypto->cmac_aes, key, 16);
+       if (fd < 0)
+               return false;
+
+       len = writev(fd, iov, iov_len);
+       if (len < 0) {
+               close(fd);
+               return false;
+       }
+
+       len = read(fd, res, 16);
+       if (len < 0) {
+               close(fd);
+               return false;
+       }
+
+       close(fd);
+
+       return true;
+}
index 1e1b483..c58d2e1 100755 (executable)
@@ -23,6 +23,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <sys/uio.h>
 
 struct bt_crypto;
 
@@ -61,3 +62,5 @@ bool bt_crypto_h6(struct bt_crypto *crypto, const uint8_t w[16],
 bool bt_crypto_sign_att(struct bt_crypto *crypto, const uint8_t key[16],
                                const uint8_t *m, uint16_t m_len,
                                uint32_t sign_cnt, uint8_t signature[12]);
+bool bt_crypto_gatt_hash(struct bt_crypto *crypto, struct iovec *iov,
+                               size_t iov_len, uint8_t res[16]);