From d0c4186b9e5ee7de1554e695364dd47b79f329e8 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Mon, 29 Jan 2018 21:20:15 +0000 Subject: [PATCH] moved fucntion impl to match position in header --- .../source/generic/GenericSecurityManager.cpp | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp index aa13b2ac03..7287cdeca5 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp @@ -434,6 +434,34 @@ void GenericSecurityManager::check_against_irk_cb( } +bool GenericSecurityManager::check_against_identity_address( + const address_t peer_address, + const irk_t *irk +) { + /* we need to verify the identity by encrypting the + * PRAND part with the IRK key and checking the result + * @see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part H - 2.2.2 */ + octet_type_t<6> prand_hash(peer_address.data(), 6); + + /* remove the hash and leave only prand */ + prand_hash[3] = 0; + prand_hash[4] = 0; + prand_hash[5] = 0; + + _pal.encrypt_data(irk, prand_hash.data()); + + /* prand_hash now contains the hash result in the first 3 octects + * compare it with the hash in the peer identity address */ + + /* can't use memcmp because of address_t constness */ + if ((prand_hash[0] == peer_address[3]) + || (prand_hash[1] == peer_address[4]) + || (prand_hash[2] == peer_address[5])) { + return true; + } + return false; +} + //////////////////////////////////////////////////////////////////////////// // Keys // @@ -922,34 +950,6 @@ void GenericSecurityManager::on_connected(connection_handle_t connection, addres entry->master = is_master; } -bool GenericSecurityManager::check_against_identity_address( - const address_t peer_address, - const irk_t *irk -) { - /* we need to verify the identity by encrypting the - * PRAND part with the IRK key and checking the result - * @see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part H - 2.2.2 */ - octet_type_t<6> prand_hash(peer_address.data(), 6); - - /* remove the hash and leave only prand */ - prand_hash[3] = 0; - prand_hash[4] = 0; - prand_hash[5] = 0; - - _pal.encrypt_data(irk, prand_hash.data()); - - /* prand_hash now contains the hash result in the first 3 octects - * compare it with the hash in the peer identity address */ - - /* can't use memcmp because of address_t constness */ - if ((prand_hash[0] == peer_address[3]) - || (prand_hash[1] == peer_address[4]) - || (prand_hash[2] == peer_address[5])) { - return true; - } - return false; -} - } /* namespace generic */ } /* namespace ble */