From ea940e67394ad58aac139d44c5586a9db98bbff7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 6 Jun 2016 18:30:36 +0200 Subject: [PATCH] shared: Add helper function for h6 link key derivation --- src/shared/crypto.c | 13 +++++++++++-- src/shared/crypto.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/shared/crypto.c b/src/shared/crypto.c index aa66dac52..6de5514c8 100644 --- a/src/shared/crypto.c +++ b/src/shared/crypto.c @@ -568,8 +568,8 @@ bool bt_crypto_s1(struct bt_crypto *crypto, const uint8_t k[16], return bt_crypto_e(crypto, k, res, res); } -static bool aes_cmac(struct bt_crypto *crypto, uint8_t key[16], uint8_t *msg, - size_t msg_len, uint8_t res[16]) +static bool aes_cmac(struct bt_crypto *crypto, const uint8_t key[16], + const uint8_t *msg, size_t msg_len, uint8_t res[16]) { uint8_t key_msb[16], out[16], msg_msb[CMAC_MSG_MAX]; ssize_t len; @@ -679,3 +679,12 @@ bool bt_crypto_g2(struct bt_crypto *crypto, uint8_t u[32], uint8_t v[32], return true; } + +bool bt_crypto_h6(struct bt_crypto *crypto, const uint8_t w[16], + const uint8_t keyid[4], uint8_t res[16]) +{ + if (!aes_cmac(crypto, w, keyid, 4, res)) + return false; + + return true; +} diff --git a/src/shared/crypto.h b/src/shared/crypto.h index 9ba5803a9..84d499280 100644 --- a/src/shared/crypto.h +++ b/src/shared/crypto.h @@ -56,6 +56,8 @@ bool bt_crypto_f6(struct bt_crypto *crypto, uint8_t w[16], uint8_t n1[16], uint8_t a1[7], uint8_t a2[7], uint8_t res[16]); bool bt_crypto_g2(struct bt_crypto *crypto, uint8_t u[32], uint8_t v[32], uint8_t x[16], uint8_t y[16], uint32_t *val); +bool bt_crypto_h6(struct bt_crypto *crypto, const uint8_t w[16], + const uint8_t keyid[4], uint8_t res[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]); -- 2.47.3