Skip to content

Commit

Permalink
shared/crypto: Adds bt_crypto_sih
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
Vudentz committed Dec 22, 2022
1 parent 90a6623 commit 5abd991
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/shared/crypto.c
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/shared/crypto.h
Expand Up @@ -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]);

0 comments on commit 5abd991

Please sign in to comment.