diff mbox series

[BlueZ,1/5] shared/crypto: Adds bt_crypto_sih

Message ID 20221222224329.685837-1-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/5] shared/crypto: Adds bt_crypto_sih | expand

Commit Message

Luiz Augusto von Dentz Dec. 22, 2022, 10:43 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(+)

Comments

patchwork-bot+bluetooth@kernel.org Jan. 3, 2023, 10:20 p.m. UTC | #1
Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu, 22 Dec 2022 14:43:25 -0800 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> 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'
> 
> [...]

Here is the summary with links:
  - [BlueZ,1/5] shared/crypto: Adds bt_crypto_sih
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5abd9914a1eb
  - [BlueZ,2/5] test-crypto: Add /crypto/sih test
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=09293fd22b3e
  - [BlueZ,3/5] shared/crypto: Adds bt_crypto_sef
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a38b6ca525b3
  - [BlueZ,4/5] test-crypto: Add /crypto/sef test
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=051ccb1e878b
  - [BlueZ,5/5] monitor: Add support for decoding RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7a32f2918035

You are awesome, thank you!
diff mbox series

Patch

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]);