diff --git a/CMakeLists.txt b/CMakeLists.txt index 746a38a..3960384 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,23 @@ if(ESP_IDF_BUILD) # Apply ESP-IDF configuration sendspin_configure_esp_idf(${COMPONENT_LIB} ${COMPONENT_DIR}) + # esphome__noise-c disables protocol name tables by default (NOISE_USE_PROTOCOL_NAME_TABLE=0), + # which pins noise-c to only Noise_NNpsk0 for the ESPHome native API. + # Sendspin uses Noise_KKpsk2, so re-enable the protocol name tables and full pattern expansion. + foreach(_noise_target esphome__noise-c __idf_esphome__noise-c) + if(TARGET ${_noise_target}) + get_target_property(_noise_defs ${_noise_target} COMPILE_DEFINITIONS) + if(_noise_defs) + list(REMOVE_ITEM _noise_defs "NOISE_USE_PROTOCOL_NAME_TABLE=0") + list(APPEND _noise_defs "NOISE_USE_PROTOCOL_NAME_TABLE=1") + set_target_properties(${_noise_target} PROPERTIES COMPILE_DEFINITIONS "${_noise_defs}") + else() + target_compile_definitions(${_noise_target} PRIVATE NOISE_USE_PROTOCOL_NAME_TABLE=1) + endif() + target_compile_options(${_noise_target} PRIVATE "-DNOISE_USE_PROTOCOL_NAME_TABLE=1") + endif() + endforeach() + # ============================================================================== # Host Build # ============================================================================== diff --git a/src/noise_session.cpp b/src/noise_session.cpp index 70733b5..2c9cf90 100644 --- a/src/noise_session.cpp +++ b/src/noise_session.cpp @@ -95,9 +95,10 @@ static NoiseHandshakeState* build_responder_hs(const std::string& suite_name, const uint8_t* prologue, size_t prologue_len, const uint8_t* psk) { NoiseHandshakeState* hs = nullptr; - if (noise_handshakestate_new_by_name(&hs, suite_name.c_str(), NOISE_ROLE_RESPONDER) != - NOISE_ERROR_NONE) { - SS_LOGE(TAG, "noise_handshakestate_new_by_name failed for suite %s", suite_name.c_str()); + int err = noise_handshakestate_new_by_name(&hs, suite_name.c_str(), NOISE_ROLE_RESPONDER); + if (err != NOISE_ERROR_NONE) { + SS_LOGE(TAG, "noise_handshakestate_new_by_name failed for suite %s (error 0x%04x: %d)", + suite_name.c_str(), err, err); return nullptr; }