Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b99776cb authored by Henri Chataing's avatar Henri Chataing
Browse files

Revert "Revert "RootCanal: Tie the random number generator to the dual mode controller instance""

This reverts commit cc83b6d2.

Reason for revert: Seed the random generator with the instance id to prevent
  random address collision

Test: avatar
Bug: 279665786
Change-Id: I7ff28899a073a7f5f496ea2cedccb92acda5ef02
parent 3c6d20f2
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@

#include <algorithm>
#include <memory>
#include <random>

#include "crypto/crypto.h"
#include "log.h"
@@ -66,7 +65,8 @@ void DualModeController::SendCommandCompleteUnknownOpCodeEvent(
}

DualModeController::DualModeController(ControllerProperties properties)
    : id_(next_instance_id()), properties_(std::move(properties)) {
    : id_(next_instance_id()), properties_(std::move(properties)),
      random_generator_(id_) {
  Address public_address{};
  ASSERT(Address::FromString("3C:5A:B4:04:05:06", public_address));
  SetAddress(public_address);
@@ -2136,17 +2136,12 @@ void DualModeController::LeEncrypt(CommandView command) {
      kNumCommandPackets, ErrorCode::SUCCESS, encrypted_data));
}

static std::random_device rd{};
static std::mt19937_64 s_mt{rd()};

void DualModeController::LeRand(CommandView command) {
  auto command_view = bluetooth::hci::LeRandView::Create(command);
  ASSERT(command_view.IsValid());

  uint64_t random_val = s_mt();

  send_event_(bluetooth::hci::LeRandCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, random_val));
      kNumCommandPackets, ErrorCode::SUCCESS, random_generator_()));
}

void DualModeController::LeReadSupportedStates(CommandView command) {
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <cstdint>
#include <memory>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
@@ -594,6 +595,9 @@ class DualModeController : public Device {
  // with RootCanal.
  bluetooth::hci::LoopbackMode loopback_mode_{LoopbackMode::NO_LOOPBACK};

  // Random value generator, always seeded with 0 to be deterministic.
  std::mt19937_64 random_generator_{};

  // Flag set to true after the HCI Reset command has been received
  // the first time.
  bool controller_reset_{false};