diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2022-12-20 14:52:10 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2022-12-21 16:30:39 -0800 |
commit | 5abd9914a1eb23e7d2b985516453f1fe7559c79f (patch) | |
tree | ca67c8450a614b0deaca35c2da1f67b169feb685 /src/shared | |
parent | 90a662392c6e9dfc25308b883d47ff1e8578646b (diff) | |
download | bluez-5abd9914a1eb23e7d2b985516453f1fe7559c79f.tar.gz |
shared/crypto: Adds bt_crypto_sih
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/
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/crypto.c | 36 | ||||
-rw-r--r-- | src/shared/crypto.h | 2 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/shared/crypto.c b/src/shared/crypto.c index d5efa416d..f164ba69d 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 356326d75..fca52e38e 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]); |