### Install Linux Prerequisites Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Installs Docker on a Linux system. ```sh sudo apt install docker ``` -------------------------------- ### Install Build Products to Raspberry Pi Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Installs the compiled HomeKit ADK applications to a Raspberry Pi using SSH. Requires hostname and password set during initial setup. ```sh ./Tools/install.sh \ -d raspi \ -a Output/Raspi-armv6k-unknown-linux-gnueabihf/Debug/IP/Applications/Lightbulb.OpenSSL \ -n raspberrypi \ -p raspberry ``` -------------------------------- ### Install Darwin Prerequisites Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Installs necessary tools like openssl, mbedtls, wget, qemu, and docker for Darwin. ```sh brew install openssl@1.1 brew install mbedtls --HEAD brew install wget brew install qemu brew install --cask docker ``` -------------------------------- ### Install C/C++ Extension for VSCode Source: https://github.com/apple/homekitadk/blob/master/Documentation/darwin_visual_debug.md Install the C/C++ language support extension for Visual Studio Code. ```shell ext install ms-vscode.cpptools ``` -------------------------------- ### Example Function with Documentation and Preconditions Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Illustrates the expected structure for functions, including Doxygen-style documentation, parameter conventions, return type handling, precondition checks, and early return patterns. ```c /** * Brief documentation about the function. * * - Remark 1 about special considerations. * * - Remark 2 about special considerations. * * @param arg1 Argument 1 documentation. * @param arg2 Argument 2 documentation. * @param[out] bytes Buffer that will be filled with data. * @param maxBytes Maximum number of bytes that may be filled into the buffer. * @param[in,out] numBytes Effective number of bytes written to the buffer. * * @return kHAPError_None If successful. * @return kHAPError_OutOfResources If the supplied buffer was not large enough. */ HAP_RESULT_USE_CHECK static HAPError HAPDoSomething( size_t arg1, bool arg2 HAP_UNUSED, void *bytes, // _Nullable if bytes are _Nullable size_t maxBytes, size_t *numBytes) // _Nullable if bytes are _Nullable { HAPPrecondition(arg1 > 42); HAPPrecondition(bytes); HAPError err; // ... return kHAPError_None; } ``` -------------------------------- ### VSCode launch.json Configuration for Lightbulb App Source: https://github.com/apple/homekitadk/blob/master/Documentation/darwin_visual_debug.md Example launch.json configuration for debugging the Lightbulb application. Ensure the 'program' path points to your application executable. ```json { "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "Debug", "program": "${workspaceFolder}/Output/Darwin-x86_64-apple-darwin19.0.0/Debug/IP/Applications/Lightbulb.OpenSSL", "args": [], "cwd": "${workspaceFolder}" } ] } ``` -------------------------------- ### Define Constant Example Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Example of defining a constant with a PascalCase name and explicit type. Consider using enumerations where appropriate. ```c /** * Brief description */ #define kHAPCategory_PascalCase ((size_t) 0x42) ``` -------------------------------- ### Documentation Block Example Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Example of a documentation block comment referencing a specification. Ensure the format matches the specification's title and section. ```c /** * ... * * @see HomeKit Accessory Protocol Specification R15 * Section 1.2.3.4 Some Sample Section */ ``` -------------------------------- ### Setup Raspberry Pi SD Card Image and Docker Container Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Creates the SD card image and Docker container for Raspberry Pi development. Ensure Docker is running before execution. ```sh # Run the Docker app. It is required for docker import. ./Tools/raspi_sdcard_setup.sh ``` -------------------------------- ### Install LLDB Debugger Extension for VSCode Source: https://github.com/apple/homekitadk/blob/master/Documentation/darwin_visual_debug.md Install the LLDB debugger extension for Visual Studio Code, required as an alternative to the default debugger. ```shell ext install vadimcn.vscode-lldb ``` -------------------------------- ### Code Comment Example Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Example of a code comment referencing a specification. Quote the specific part of the spec being referenced. ```c // ... // See HomeKit Accessory Protocol Specification R15 // Section 1.2.3.4 Some Sample Section ``` -------------------------------- ### Enum Definition with Documentation Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Example of defining an enumeration using HAP_ENUM_BEGIN and HAP_ENUM_END macros, including Doxygen-style comments for the enum type and its cases. This ensures portability and consistent documentation. ```c /** * Enum type documentation. */ HAP_ENUM_BEGIN(uint8_t, HAPEnumType) { kHAPEnumType_PascalCase1, /**< Case 1 documentation. */ kHAPEnumType_PascalCase2, /**< Case 2 documentation. */ /** * Case 3 documentation. * * - Remark 1. * * - Remark 2. */ kHAPEnumType_ReallyReallyLongCase, /** Case 4 documentation. */ kHAPEnumType_ReallyReallyLongCase2 } HAP_ENUM_END(uint8_t, HAPEnumType); ``` -------------------------------- ### Install Git Pre-commit Hook Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Copy the pre-commit hook script to enable linting checks at commit time. This hook validates staged files without reformatting. ```bash cp Tools/linters/git-hooks-pre-commit .git/hooks/pre-commit ``` -------------------------------- ### Generate HTML Documentation Source: https://github.com/apple/homekitadk/blob/master/README.md Run this command to generate HTML documentation from markdown files. The generated webpage can be opened in a browser. ```sh make docs ``` -------------------------------- ### Run Linting Script Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Execute the main linting script to check code style and formatting. Use this before submitting a Pull Request. ```bash ./Tools/linters/lint.sh -h ``` -------------------------------- ### Standard C Header File Structure Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md This C code demonstrates the standard structure for header files in the HomeKit ADK, including header guards, include directives, and extern "C" declarations. ```c #ifndef HAP_HEADER_FILE_NAME_H #define HAP_HEADER_FILE_NAME_H #ifdef __cplusplus extern "C" { #endif #include #include "platform_header.h" #include "HAPPlatform.h" #if __has_feature(nullability) #pragma clang assume_nonnull begin #endif // Header file contents. #if __has_feature(nullability) #pragma clang assume_nonnull end #endif #ifdef __cplusplus } #endif #endif ``` -------------------------------- ### Run HomeKit ADK Application on Darwin Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Executes the compiled Lightbulb application on Darwin. ```sh ./Output/Darwin-x86_64-apple-darwin$(uname -r)/Debug/IP/Applications/Lightbulb.OpenSSL ``` -------------------------------- ### Compile HomeKit ADK on Darwin Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Compiles the HomeKit ADK for the Darwin platform. ```sh make all ``` -------------------------------- ### Compile HomeKit ADK on Linux Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Compiles the HomeKit ADK applications for the Linux target. ```sh make TARGET=Linux apps ``` -------------------------------- ### Compile HomeKit ADK for Raspberry Pi Source: https://github.com/apple/homekitadk/blob/master/Documentation/getting_started.md Compiles the HomeKit ADK for the Raspberry Pi target. ```sh make TARGET=Raspi all ``` -------------------------------- ### Opaque Structure Assertion (Private Header) Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Specifies the real structure in a private header and uses HAP_STATIC_ASSERT to ensure it fits within the opaque reference size. ```c HAP_STATIC_ASSERT(sizeof (HAPFooRef) >= sizeof (HAPFoo), HAPFoo); ``` -------------------------------- ### Accessing Opaque Structure Fields Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Demonstrates how to access internal fields of an opaque structure by casting the reference to the actual structure pointer. This is typically done in internal implementation files. ```c HAPFooRef *foo_; HAPFoo *foo = (HAPFoo *) foo_; ``` -------------------------------- ### Switch Statement with Scoped Cases and Break Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md This C code illustrates a switch statement with separate scopes for each case, using 'break;' or '// Fallthrough.' comments as required. ```c switch (foo) { case 'a': { // Handle case. } break; case 'b': { // Handle case. } break; case 'c': case 'd': { // Handle cases. } // Fallthrough. case 'e': { // Handle case. } break; } ``` -------------------------------- ### SRP6a Protocol Constants and Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Defines constants for SRP6a protocol parameters and function signatures for SRP6a operations. This implementation is provided by the ADK and can be replaced by a custom one. ```c #define SRP_PRIME_BYTES 384 #define SRP_SALT_BYTES 16 #define SRP_VERIFIER_BYTES 384 #define SRP_SECRET_KEY_BYTES 32 #define SRP_PUBLIC_KEY_BYTES 384 #define SRP_SCRAMBLING_PARAMETER_BYTES 64 #define SRP_PREMASTER_SECRET_BYTES 384 #define SRP_SESSION_KEY_BYTES 64 #define SRP_PROOF_BYTES 64 void HAP_srp_verifier(uint8_t v[SRP_VERIFIER_BYTES], const uint8_t salt[SRP_SALT_BYTES], const uint8_t *user, size_t user_len, const uint8_t *pass, size_t pass_len); void HAP_srp_public_key(uint8_t pub_b[SRP_PUBLIC_KEY_BYTES], const uint8_t priv_b[SRP_SECRET_KEY_BYTES], const uint8_t v[SRP_VERIFIER_BYTES]); void HAP_srp_scrambling_parameter(uint8_t u[SRP_SCRAMBLING_PARAMETER_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t pub_b[SRP_PUBLIC_KEY_BYTES]); int HAP_srp_premaster_secret(uint8_t s[SRP_PREMASTER_SECRET_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t priv_b[SRP_SECRET_KEY_BYTES], const uint8_t u[SRP_SCRAMBLING_PARAMETER_BYTES], const uint8_t v[SRP_VERIFIER_BYTES]); void HAP_srp_session_key(uint8_t k[SRP_SESSION_KEY_BYTES], const uint8_t s[SRP_PREMASTER_SECRET_BYTES]); void HAP_srp_proof_m1(uint8_t m1[SRP_PROOF_BYTES], const uint8_t *user, size_t user_len, const uint8_t salt[SRP_SALT_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t pub_b[SRP_PUBLIC_KEY_BYTES], const uint8_t k[SRP_SESSION_KEY_BYTES]); void HAP_srp_proof_m2(uint8_t m2[SRP_PROOF_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t m1[SRP_PROOF_BYTES], const uint8_t k[SRP_SESSION_KEY_BYTES]); ``` -------------------------------- ### SHA Hashing Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides function signatures for SHA1, SHA-256, and SHA-512 hashing algorithms. These functions compute the message digest for given input data. ```c #define SHA1_BYTES 20 void HAP_sha1(uint8_t md[SHA1_BYTES], const uint8_t *data, size_t size); ``` ```c #define SHA256_BYTES 32 void HAP_sha256(uint8_t md[SHA256_BYTES], const uint8_t *data, size_t size); ``` ```c #define SHA512_BYTES 64 void HAP_sha512(uint8_t md[SHA512_BYTES], const uint8_t *data, size_t size); ``` -------------------------------- ### PBKDF2-SHA1 Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides a function for a brute-force resistant password-based key derivation function using PBKDF2-SHA1. ```APIDOC ## PBKDF2-SHA1 ### Description Provides a function for a brute-force resistant password-based key derivation function using PBKDF2-SHA1. ### Function - `HAP_pbkdf2_hmac_sha1(uint8_t *key, size_t key_len, const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint32_t count)`: Derives a key using PBKDF2-SHA1. ``` -------------------------------- ### Switch Statement for Enum Description with Early Return Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md This C code shows a switch statement used for converting an enum to its string description, employing early returns for each case and a default fatal error. ```c static const char *GetCurrentHeatingCoolingStateDescription( HAPCharacteristicValue_CurrentHeatingCoolingState state) { switch (state) { case kHAPCharacteristicValue_CurrentHeatingCoolingState_Off: return "Off."; case kHAPCharacteristicValue_CurrentHeatingCoolingState_Heat: return "Heat. The Heater is currently on."; case kHAPCharacteristicValue_CurrentHeatingCoolingState_Cool: return "Cool. Cooler is currently on."; default: HAPFatalError(); } } ``` -------------------------------- ### Opaque Structure Definition (Public Header) Source: https://github.com/apple/homekitadk/blob/master/Documentation/coding_convention.md Defines an opaque structure in a public header using the HAP_OPAQUE macro. The first argument specifies the size in multiples of 8 bytes. ```c typedef HAP_OPAQUE(24) HAPFooRef; ``` -------------------------------- ### SHA Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides functions for Secure Hash Algorithms SHA1, SHA-256, and SHA-512. ```APIDOC ## SHA Functions ### Description Provides functions for Secure Hash Algorithms SHA1, SHA-256, and SHA-512. ### Functions - `HAP_sha1(uint8_t md[SHA1_BYTES], const uint8_t *data, size_t size)`: Computes the SHA1 hash. - `HAP_sha256(uint8_t md[SHA256_BYTES], const uint8_t *data, size_t size)`: Computes the SHA-256 hash. - `HAP_sha512(uint8_t md[SHA512_BYTES], const uint8_t *data, size_t size)`: Computes the SHA-512 hash. ``` -------------------------------- ### PBKDF2-SHA1 Function Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Signature for PBKDF2-SHA1, a password-based key derivation function. It is brute-force resistant and uses SHA1. ```c void HAP_pbkdf2_hmac_sha1(uint8_t *key, size_t key_len, const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint32_t count); ``` -------------------------------- ### ChaCha20 Poly1305 Single-Shot API Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides single-shot API for ChaCha20 Poly1305 encryption and decryption, recommended for BLE-only crypto backends. The streaming API is required by IP accessories. ```c void HAP_chacha20_poly1305_encrypt_aad(uint8_t tag[CHACHA20_POLY1305_TAG_BYTES], uint8_t *c, const uint8_t *m, size_t m_len, const uint8_t *a, size_t a_len, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); int HAP_chacha20_poly1305_decrypt_aad(const uint8_t tag[CHACHA20_POLY1305_TAG_BYTES], uint8_t *m, const uint8_t *c, size_t c_len, const uint8_t *a, size_t a_len, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); ``` -------------------------------- ### HKDF-SHA512 Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides a function for HMAC-based key derivation using SHA-512. ```APIDOC ## HKDF-SHA512 ### Description Provides a function for HMAC-based key derivation using SHA-512. ### Function - `HAP_hkdf_sha512(uint8_t* r, size_t r_len, const uint8_t* key, size_t key_len, const uint8_t* salt, size_t salt_len, const uint8_t* info, size_t info_len)`: Derives a key using HKDF-SHA512. ``` -------------------------------- ### SRP6a Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides functions for the Secure Remote Password protocol (SRP6a), a password-authenticated key agreement protocol. ```APIDOC ## SRP6a Functions ### Description Provides functions for the Secure Remote Password protocol (SRP6a), a password-authenticated key agreement protocol. ### Functions - `HAP_srp_verifier(uint8_t v[SRP_VERIFIER_BYTES], const uint8_t salt[SRP_SALT_BYTES], const uint8_t *user, size_t user_len, const uint8_t *pass, size_t pass_len)`: Computes the SRP verifier. - `HAP_srp_public_key(uint8_t pub_b[SRP_PUBLIC_KEY_BYTES], const uint8_t priv_b[SRP_SECRET_KEY_BYTES], const uint8_t v[SRP_VERIFIER_BYTES])`: Computes the SRP public key. - `HAP_srp_scrambling_parameter(uint8_t u[SRP_SCRAMBLING_PARAMETER_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t pub_b[SRP_PUBLIC_KEY_BYTES])`: Computes the SRP scrambling parameter. - `HAP_srp_premaster_secret(uint8_t s[SRP_PREMASTER_SECRET_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t priv_b[SRP_SECRET_KEY_BYTES], const uint8_t u[SRP_SCRAMBLING_PARAMETER_BYTES], const uint8_t v[SRP_VERIFIER_BYTES])`: Computes the SRP premaster secret. - `HAP_srp_session_key(uint8_t k[SRP_SESSION_KEY_BYTES], const uint8_t s[SRP_PREMASTER_SECRET_BYTES])`: Computes the SRP session key. - `HAP_srp_proof_m1(uint8_t m1[SRP_PROOF_BYTES], const uint8_t *user, size_t user_len, const uint8_t salt[SRP_SALT_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t pub_b[SRP_PUBLIC_KEY_BYTES], const uint8_t k[SRP_SESSION_KEY_BYTES])`: Computes the SRP proof M1. - `HAP_srp_proof_m2(uint8_t m2[SRP_PROOF_BYTES], const uint8_t pub_a[SRP_PUBLIC_KEY_BYTES], const uint8_t m1[SRP_PROOF_BYTES], const uint8_t k[SRP_SESSION_KEY_BYTES])`: Computes the SRP proof M2. ``` -------------------------------- ### ChaCha20 Poly1305 Single-Shot API Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides single-shot functions for ChaCha20 Poly1305 encryption and decryption with additional authenticated data. This API is recommended for BLE-only crypto backends if `HAVE_CUSTOM_SINGLE_SHOT_CHACHA20_POLY1305` is defined. ```APIDOC ## ChaCha20 Poly1305 Single-Shot API ### Description Provides single-shot functions for ChaCha20 Poly1305 encryption and decryption with additional authenticated data. This API is synthesized from the streaming API if `HAVE_CUSTOM_SINGLE_SHOT_CHACHA20_POLY1305` is not set. It is recommended for BLE-only crypto backends. ### Functions #### `HAP_chacha20_poly1305_encrypt_aad` Performs ChaCha20 Poly1305 encryption in a single call, including additional authenticated data (AAD). #### `HAP_chacha20_poly1305_decrypt_aad` Performs ChaCha20 Poly1305 decryption in a single call, including additional authenticated data (AAD). Returns 0 on success, non-zero on failure. ### Parameters - For `HAP_chacha20_poly1305_decrypt_aad`, `a_len` might be NULL. ``` -------------------------------- ### Ed25519 Cryptographic Constants and Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Defines constants for Ed25519 key and signature sizes and declares functions for public key generation, signing, and signature verification. This implementation is provided by the HomeKit ADK for MbedTLS. ```c #define ED25519_PUBLIC_KEY_BYTES 32 #define ED25519_SECRET_KEY_BYTES 32 #define ED25519_BYTES 64 void HAP_ed25519_public_key(uint8_t pk[ED25519_PUBLIC_KEY_BYTES], const uint8_t sk[ED25519_SECRET_KEY_BYTES]); void HAP_ed25519_sign(uint8_t sig[ED25519_BYTES], const uint8_t *m, size_t m_len, const uint8_t sk[ED25519_SECRET_KEY_BYTES], const uint8_t pk[ED25519_PUBLIC_KEY_BYTES]); int HAP_ed25519_verify(const uint8_t sig[ED25519_BYTES], const uint8_t *m, size_t m_len, const uint8_t pk[ED25519_PUBLIC_KEY_BYTES]); ``` -------------------------------- ### X25519 Cryptographic Constants and Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Defines constants for X25519 scalar and public key sizes and declares functions for base scalar multiplication and general scalar multiplication. These are used for Diffie-Hellman key exchange. ```c #define X25519_SCALAR_BYTES 32 #define X25519_BYTES 32 void HAP_X25519_scalarmult_base(uint8_t r[X25519_BYTES], const uint8_t n[X25519_SCALAR_BYTES]); void HAP_X25519_scalarmult(uint8_t r[X25519_BYTES], const uint8_t n[X25519_SCALAR_BYTES], const uint8_t p[X25519_BYTES]); ``` -------------------------------- ### ChaCha20 Poly1305 Streaming API Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Functions for initializing, updating, and finalizing ChaCha20 Poly1305 encryption and decryption operations using a streaming approach. Supports overlapping buffers for message and ciphertext. ```APIDOC ## ChaCha20 Poly1305 Streaming API ### Description Provides functions for initializing, updating, and finalizing ChaCha20 Poly1305 encryption and decryption operations using a streaming approach. This API is required by IP accessories. ### Functions #### `HAP_chacha20_poly1305_init` Initializes the ChaCha20 Poly1305 context. #### `HAP_chacha20_poly1305_update_enc` Encrypts a portion of the message and updates the context. Supports overlapping buffers for message (m) and ciphertext (c). #### `HAP_chacha20_poly1305_update_enc_aad` Processes additional authenticated data (AAD) for encryption. #### `HAP_chacha20_poly1305_final_enc` Finalizes the encryption process and generates the authentication tag. #### `HAP_chacha20_poly1305_update_dec` Decrypts a portion of the ciphertext and updates the context. Supports overlapping buffers for ciphertext (c) and message (m). #### `HAP_chacha20_poly1305_update_dec_aad` Processes additional authenticated data (AAD) for decryption. #### `HAP_chacha20_poly1305_final_dec` Finalizes the decryption process and verifies the authentication tag. Returns 0 on success, non-zero on failure. ### Constants - `CHACHA20_POLY1305_KEY_BYTES`: 32 - `CHACHA20_POLY1305_NONCE_BYTES_MAX`: 12 - `CHACHA20_POLY1305_TAG_BYTES`: 16 ### Notes * The implementation must support overlapping buffers (m and c). ``` -------------------------------- ### AES-CTR Mode Functions Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides functions for AES block cipher in Counter (CTR) mode for encryption and decryption. This is only needed for IP Accessories. ```c void HAP_aes_ctr_init(HAP_aes_ctr_ctx *ctx, const uint8_t *key, int size, const uint8_t iv[16]); void HAP_aes_ctr_encrypt(HAP_aes_ctr_ctx *ctx, uint8_t* ct, const uint8_t* pt, size_t pt_len); void HAP_aes_ctr_decrypt(HAP_aes_ctr_ctx *ctx, uint8_t* pt, const uint8_t* ct, size_t ct_len); void HAP_aes_ctr_done(HAP_aes_ctr_ctx *ctx); ``` -------------------------------- ### ChaCha20 Poly1305 Streaming API Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Defines the streaming API for ChaCha20 Poly1305 encryption and decryption. The implementation must support overlapping buffers for message and ciphertext. ```c #define CHACHA20_POLY1305_KEY_BYTES 32 #define CHACHA20_POLY1305_NONCE_BYTES_MAX 12 #define CHACHA20_POLY1305_TAG_BYTES 16 void HAP_chacha20_poly1305_init(HAP_chacha20_poly1305_ctx *ctx, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); void HAP_chacha20_poly1305_update_enc(HAP_chacha20_poly1305_ctx *ctx, uint8_t *c, const uint8_t *m, size_t m_len, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); void HAP_chacha20_poly1305_update_enc_aad(HAP_chacha20_poly1305_ctx *ctx, const uint8_t *a, size_t a_len, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); void HAP_chacha20_poly1305_final_enc(HAP_chacha20_poly1305_ctx *ctx, uint8_t tag[CHACHA20_POLY1305_TAG_BYTES]); void HAP_chacha20_poly1305_update_dec(HAP_chacha20_poly1305_ctx *ctx, uint8_t *m, const uint8_t *c, size_t c_len, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); void HAP_chacha20_poly1305_update_dec_aad(HAP_chacha20_poly1305_ctx *ctx, const uint8_t *a, size_t a_len, const uint8_t *n, size_t n_len, const uint8_t k[CHACHA20_POLY1305_KEY_BYTES]); int HAP_chacha20_poly1305_final_dec(HAP_chacha20_poly1305_ctx *ctx, const uint8_t tag[CHACHA20_POLY1305_TAG_BYTES]); ``` -------------------------------- ### HMAC-SHA1 Function Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Signature for HMAC-SHA1 calculation, used for message authentication. This is primarily needed for IP Accessories. ```c #define HMAC_SHA1_BYTES SHA1_BYTES void HAP_hmac_sha1_aad(uint8_t r[HMAC_SHA1_BYTES], const uint8_t* key, size_t key_len, const uint8_t* in, size_t in_len, const uint8_t* aad, size_t aad_len); ``` -------------------------------- ### AES-CTR Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides functions for AES block cipher in CTR mode, primarily for IP Accessories. ```APIDOC ## AES-CTR ### Description Provides functions for AES block cipher in CTR mode. Only needed for IP Accessories. ### Functions - `HAP_aes_ctr_init(HAP_aes_ctr_ctx *ctx, const uint8_t *key, int size, const uint8_iv[16])`: Initializes the AES-CTR context. - `HAP_aes_ctr_encrypt(HAP_aes_ctr_ctx *ctx, uint8_t* ct, const uint8_t* pt, size_t pt_len)`: Encrypts data using AES-CTR. - `HAP_aes_ctr_decrypt(HAP_aes_ctr_ctx *ctx, uint8_t* pt, const uint8_t* ct, size_t ct_len)`: Decrypts data using AES-CTR. - `HAP_aes_ctr_done(HAP_aes_ctr_ctx *ctx)`: Cleans up the AES-CTR context. ``` -------------------------------- ### HKDF-SHA512 Function Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Signature for HKDF-SHA512, a key derivation function based on HMAC-SHA512. Used for generating keys from a shared secret. ```c void HAP_hkdf_sha512(uint8_t* r, size_t r_len, const uint8_t* key, size_t key_len, const uint8_t* salt, size_t salt_len, const uint8_t* info, size_t info_len); ``` -------------------------------- ### HMAC SHA1 Source: https://github.com/apple/homekitadk/blob/master/Documentation/crypto.md Provides a function for Hash-based message authentication code using SHA1, primarily for IP Accessories. ```APIDOC ## HMAC SHA1 ### Description Provides a function for Hash-based message authentication code using SHA1. Only needed for IP Accessories. ### Function - `HAP_hmac_sha1_aad(uint8_t r[HMAC_SHA1_BYTES], const uint8_t* key, size_t key_len, const uint8_t* in, size_t in_len, const uint8_t* aad, size_t aad_len)`: Computes the HMAC SHA1 with additional authenticated data. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.