From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> This adds bt_crypto_sih is is used to create a hash as stated on CSIS[1] spec: '4.7. Resolvable Set Identifier hash function sih' https://www.bluetooth.com/specifications/csis-1-0-1/ --- src/shared/crypto.c | 36 ++++++++++++++++++++++++++++++++++++ src/shared/crypto.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/src/shared/crypto.c b/src/shared/crypto.c index d5efa416dd99..f164ba69d2a5 100644 --- a/src/shared/crypto.c +++ b/src/shared/crypto.c @@ -737,3 +737,39 @@ bool bt_crypto_gatt_hash(struct bt_crypto *crypto, struct iovec *iov, return true; } + +/* + * Resolvable Set Identifier hash function sih + * + * The RSI hash function sih is used to generate a hash value that is used in + * RSIs. + * + * The following variables are the inputs to the RSI hash function sih: + * + * k is 128 bits + * r is 24 bits + * padding is 104 bits, all set to 0 + * + * r is concatenated with padding to generate r', which is used as the 128-bit + * input parameter plaintextData to security function e: + * + * r'=padding||r + * + * The LSO of r becomes the LSO of r', and the MSO of padding becomes the MSO + * of r'. + * + * For example, if the 24-bit value r is 0x3A98B5, then r' is + * 0x000000000000000000000000003A98B5. + * + * The output of the Resolvable Set Identifier function sih is: + * + * sih(k, r)=e(k, r') mod 2^24 + * + * The output of the security function e is truncated to 24 bits by taking the + * least significant 24 bits of the output of e as the result of sih. + */ +bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16], + const uint8_t r[3], uint8_t hash[3]) +{ + return bt_crypto_ah(crypto, k, r, hash); +} diff --git a/src/shared/crypto.h b/src/shared/crypto.h index 356326d75408..fca52e38e5e2 100644 --- a/src/shared/crypto.h +++ b/src/shared/crypto.h @@ -53,3 +53,5 @@ bool bt_crypto_verify_att_sign(struct bt_crypto *crypto, const uint8_t key[16], const uint8_t *pdu, uint16_t pdu_len); bool bt_crypto_gatt_hash(struct bt_crypto *crypto, struct iovec *iov, size_t iov_len, uint8_t res[16]); +bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16], + const uint8_t r[3], uint8_t hash[3]); -- 2.37.3