Skip to content

Commit 53776fe

Browse files
authored
Merge pull request #14125 from pan-/fix-sm-key-generation
BLE: Fix Security Manager key generation
2 parents 549f887 + 4cfcadd commit 53776fe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

connectivity/FEATURE_BLE/source/generic/SecurityManagerImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ ble_error_t SecurityManager::init_signing()
10541054
sign_count_t local_sign_counter = _db->get_local_sign_counter();
10551055

10561056
csrk_t csrk;
1057-
if (!pcsrk) {
1057+
if (!pcsrk || *pcsrk == csrk_t{}) {
10581058
ble_error_t ret = get_random_data(csrk.data(), csrk.size());
10591059
if (ret != BLE_ERROR_NONE) {
10601060
return ret;
@@ -1125,7 +1125,7 @@ ble_error_t SecurityManager::get_random_data(uint8_t *buffer, size_t size)
11251125
while (size) {
11261126
/* fill out the buffer by reading the random data in chunks
11271127
* and copying it until reaching the set size */
1128-
size_t copy_size = std::max(size, random_data.size());
1128+
size_t copy_size = std::min(size, random_data.size());
11291129
ble_error_t ret = _pal.get_random_data(random_data);
11301130
if (ret != BLE_ERROR_NONE) {
11311131
return ret;

0 commit comments

Comments
 (0)