1 /* 2 * Copyright (c) 2019 Bose Corporation 3 * Copyright (c) 2021-2022 Nordic Semiconductor ASA 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #include <stdint.h> 9 10 #include <zephyr/bluetooth/audio/csip.h> 11 #include <zephyr/types.h> 12 13 #define BT_CSIP_CRYPTO_KEY_SIZE 16 14 #define BT_CSIP_CRYPTO_SALT_SIZE 16 15 #define BT_CSIP_CRYPTO_PRAND_SIZE 3 16 #define BT_CSIP_CRYPTO_HASH_SIZE 3 17 18 /** 19 * @brief Private Set Unique identifier hash function sih. 20 * 21 * The RSI hash function sih is used to generate a hash value that is 22 * used in RSIs - Used by the Coordinated Set Identification service and 23 * profile. 24 * 25 * @param sirk 16-byte SIRK in little-endian byte order. 26 * @param r 3-byte random value in little-endian byte order. 27 * @param out 3-byte output buffer in little-endian byte order. 28 * 29 * @return int 0 on success, any other value indicates a failure. 30 */ 31 int bt_csip_sih(const uint8_t sirk[BT_CSIP_SIRK_SIZE], uint8_t r[BT_CSIP_CRYPTO_PRAND_SIZE], 32 uint8_t out[BT_CSIP_CRYPTO_HASH_SIZE]); 33 34 /** 35 * @brief SIRK encryption function sef 36 * 37 * The SIRK encryption function sef is used by the server to encrypt the SIRK 38 * with a key K. The value of K depends on the transport on which the pairing 39 * between the client and the server was performed. 40 * 41 * If the pairing was performed on Basic Rate/Enhanced Data Rate (BR/EDR), K is equal to the 42 * Link Key shared by the server and the client. 43 * K = Link Key. 44 * 45 * If the pairing was performed on Bluetooth Low Energy (LE), K is equal to the LTK shared by the 46 * server and client. That is, 47 * K = LTK 48 * 49 * @param k 16-byte key in little-endian byte order. 50 * @param sirk 16-byte unencrypted SIRK key in little-endian byte order. 51 * @param out_sirk 16-byte encrypted SIRK key in little-endian byte order. 52 * 53 * @return int 0 on success, any other value indicates a failure. 54 */ 55 int bt_csip_sef(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE], const uint8_t sirk[BT_CSIP_SIRK_SIZE], 56 uint8_t out_sirk[BT_CSIP_SIRK_SIZE]); 57 58 /** 59 * @brief SIRK decryption function sdf 60 * 61 * The SIRK decryption function sdf is used by the client to decrypt the SIRK 62 * with a key K. The value of K depends on the transport on which the pairing 63 * between the client and the server was performed. 64 * 65 * If the pairing was performed on Basic Rate/Enhanced Data Rate (BR/EDR), K is equal to the 66 * Link Key shared by the server and the client. 67 * K = Link Key. 68 * 69 * If the pairing was performed on Bluetooth Low Energy (LE), K is equal to the LTK shared by the 70 * server and client. That is, 71 * K = LTK 72 * 73 * @param k 16-byte key in little-endian byte order. 74 * @param sirk 16-byte encrypted SIRK in little-endian byte order. 75 * @param out_sirk 16-byte decrypted SIRK in little-endian byte order. 76 * 77 * @return int 0 on success, any other value indicates a failure. 78 */ 79 int bt_csip_sdf(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE], const uint8_t enc_sirk[BT_CSIP_SIRK_SIZE], 80 uint8_t out_sirk[BT_CSIP_SIRK_SIZE]); 81