Merge pull request #14125 from pan-/fix-sm-key-generation

BLE: Fix Security Manager key generation
pull/14403/head
Martin Kojtal 2021-01-11 13:39:19 +00:00 committed by GitHub
commit 53776fec43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -1054,7 +1054,7 @@ ble_error_t SecurityManager::init_signing()
sign_count_t local_sign_counter = _db->get_local_sign_counter();
csrk_t csrk;
if (!pcsrk) {
if (!pcsrk || *pcsrk == csrk_t{}) {
ble_error_t ret = get_random_data(csrk.data(), csrk.size());
if (ret != BLE_ERROR_NONE) {
return ret;
@ -1125,7 +1125,7 @@ ble_error_t SecurityManager::get_random_data(uint8_t *buffer, size_t size)
while (size) {
/* fill out the buffer by reading the random data in chunks
* and copying it until reaching the set size */
size_t copy_size = std::max(size, random_data.size());
size_t copy_size = std::min(size, random_data.size());
ble_error_t ret = _pal.get_random_data(random_data);
if (ret != BLE_ERROR_NONE) {
return ret;