Re: [PATCH BlueZ 01/15] shared/crypto: Add bt_crypto_gatt_hash

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

 



Hi,
On Tue, Jan 29, 2019 at 3:26 PM Luiz Augusto von Dentz
<luiz.dentz@xxxxxxxxx> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>
>
> 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.
> ---
>  src/shared/crypto.c | 31 +++++++++++++++++++++++++++++++
>  src/shared/crypto.h |  3 +++
>  2 files changed, 34 insertions(+)
>
> diff --git a/src/shared/crypto.c b/src/shared/crypto.c
> index ce0dcd638..5c5e1217d 100644
> --- a/src/shared/crypto.c
> +++ b/src/shared/crypto.c
> @@ -688,3 +688,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;
> +}
> diff --git a/src/shared/crypto.h b/src/shared/crypto.h
> index 1e1b4836d..c58d2e104 100644
> --- a/src/shared/crypto.h
> +++ b/src/shared/crypto.h
> @@ -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]);
> --
> 2.17.2

Applied.

-- 
Luiz Augusto von Dentz



[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