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

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

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

Seed the generator with the value 0, in order to provide a deterministic
environment for connected hosts.

Bug: 279665786
Test: m root-canal
Change-Id: If3055f1b73c3539af049cb305fca9b5ae6188c76
parent 9068f477
Loading
Loading
Loading
Loading
+1 −7
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@


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


#include "crypto/crypto.h"
#include "crypto/crypto.h"
#include "log.h"
#include "log.h"
@@ -2246,17 +2245,12 @@ void DualModeController::LeEncrypt(CommandView command) {
      kNumCommandPackets, ErrorCode::SUCCESS, encrypted_data));
      kNumCommandPackets, ErrorCode::SUCCESS, encrypted_data));
}
}


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

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


  uint64_t random_val = s_mt();

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


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


#include <cstdint>
#include <cstdint>
#include <memory>
#include <memory>
#include <random>
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_map>
#include <vector>
#include <vector>
@@ -562,7 +563,6 @@ class DualModeController : public Device {
  void WriteConnectionAcceptTimeout(CommandView command);
  void WriteConnectionAcceptTimeout(CommandView command);


  // Vendor-specific Commands
  // Vendor-specific Commands

  void LeGetVendorCapabilities(CommandView command);
  void LeGetVendorCapabilities(CommandView command);
  void LeEnergyInfo(CommandView command);
  void LeEnergyInfo(CommandView command);
  void LeMultiAdv(CommandView command);
  void LeMultiAdv(CommandView command);
@@ -606,6 +606,9 @@ class DualModeController : public Device {
  // with RootCanal.
  // with RootCanal.
  bluetooth::hci::LoopbackMode loopback_mode_{LoopbackMode::NO_LOOPBACK};
  bluetooth::hci::LoopbackMode loopback_mode_{LoopbackMode::NO_LOOPBACK};


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

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