Loading system/gd/crypto_toolbox/crypto_toolbox.cc +38 −0 Original line number Diff line number Diff line Loading @@ -161,5 +161,43 @@ Octet16 link_key_to_ltk(const Octet16& link_key, bool use_h7) { return h6(iltk, keyID_brle); } Octet16 c1(const Octet16& k, const Octet16& r, const uint8_t* pres, const uint8_t* preq, const uint8_t iat, const uint8_t* ia, const uint8_t rat, const uint8_t* ra) { Octet16 p1; auto it = p1.begin(); it = std::copy(pres, pres + 7, it); it = std::copy(preq, preq + 7, it); it = std::copy(&rat, &rat + 1, it); it = std::copy(&iat, &iat + 1, it); for (uint8_t i = 0; i < OCTET16_LEN; i++) { p1[i] = r[i] ^ p1[i]; } Octet16 p1bis = aes_128(k, p1); std::array<uint8_t, 4> padding{0}; Octet16 p2; it = p2.begin(); it = std::copy(padding.begin(), padding.end(), it); it = std::copy(ia, ia + 6, it); it = std::copy(ra, ra + 6, it); for (uint8_t i = 0; i < OCTET16_LEN; i++) { p2[i] = p1bis[i] ^ p2[i]; } return aes_128(k, p2); } Octet16 s1(const Octet16& k, const Octet16& r1, const Octet16& r2) { Octet16 text{0}; constexpr uint8_t BT_OCTET8_LEN = 8; memcpy(text.data(), r1.data(), BT_OCTET8_LEN); memcpy(text.data() + BT_OCTET8_LEN, r2.data(), BT_OCTET8_LEN); return aes_128(k, text); } } // namespace crypto_toolbox } // namespace bluetooth No newline at end of file system/gd/crypto_toolbox/crypto_toolbox.h +4 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,10 @@ namespace crypto_toolbox { constexpr int OCTET16_LEN = 16; using Octet16 = std::array<uint8_t, OCTET16_LEN>; Octet16 c1(const Octet16& k, const Octet16& r, const uint8_t* pres, const uint8_t* preq, const uint8_t iat, const uint8_t* ia, const uint8_t rat, const uint8_t* ra); Octet16 s1(const Octet16& k, const Octet16& r1, const Octet16& r2); extern Octet16 aes_128(const Octet16& key, const Octet16& message); extern Octet16 aes_cmac(const Octet16& key, const uint8_t* message, uint16_t length); extern Octet16 f4(uint8_t* u, uint8_t* v, const Octet16& x, uint8_t z); Loading system/gd/hci/hci_layer.cc +4 −4 Original line number Diff line number Diff line Loading @@ -441,7 +441,7 @@ void HciLayer::UnregisterLeEventHandler(SubeventCode subevent_code) { impl_->UnregisterLeEventHandler(subevent_code); } const SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler) { for (const auto event : SecurityInterface::SecurityEvents) { RegisterEventHandler(event, event_handler, handler); Loading @@ -449,7 +449,7 @@ const SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(Ev return &impl_->security_interface; } const LeSecurityInterface* HciLayer::GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, LeSecurityInterface* HciLayer::GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, os::Handler* handler) { for (const auto subevent : LeSecurityInterface::LeSecurityEvents) { RegisterLeEventHandler(subevent, event_handler, handler); Loading system/gd/hci/hci_layer.h +3 −4 Original line number Diff line number Diff line Loading @@ -57,10 +57,9 @@ class HciLayer : public Module { virtual void UnregisterLeEventHandler(SubeventCode subevent_code); const SecurityInterface* GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler); SecurityInterface* GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler); const LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, os::Handler* handler); static const ModuleFactory Factory; Loading system/gd/hci/hci_packets.pdl +6 −2 Original line number Diff line number Diff line Loading @@ -2177,11 +2177,15 @@ packet LeRandComplete : CommandComplete (command_op_code = LE_RAND) { } packet LeStartEncryption : LeSecurityCommand (op_code = LE_START_ENCRYPTION) { _payload_, // placeholder (unimplemented) connection_handle: 16, rand: 8[8], ediv: 16, ltk: 8[16], } packet LeLongTermKeyRequestReply : LeSecurityCommand (op_code = LE_LONG_TERM_KEY_REQUEST_REPLY) { _payload_, // placeholder (unimplemented) connection_handle: 16, long_term_key: 8[16], } packet LeLongTermKeyRequestNegativeReply : LeSecurityCommand (op_code = LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY) { Loading Loading
system/gd/crypto_toolbox/crypto_toolbox.cc +38 −0 Original line number Diff line number Diff line Loading @@ -161,5 +161,43 @@ Octet16 link_key_to_ltk(const Octet16& link_key, bool use_h7) { return h6(iltk, keyID_brle); } Octet16 c1(const Octet16& k, const Octet16& r, const uint8_t* pres, const uint8_t* preq, const uint8_t iat, const uint8_t* ia, const uint8_t rat, const uint8_t* ra) { Octet16 p1; auto it = p1.begin(); it = std::copy(pres, pres + 7, it); it = std::copy(preq, preq + 7, it); it = std::copy(&rat, &rat + 1, it); it = std::copy(&iat, &iat + 1, it); for (uint8_t i = 0; i < OCTET16_LEN; i++) { p1[i] = r[i] ^ p1[i]; } Octet16 p1bis = aes_128(k, p1); std::array<uint8_t, 4> padding{0}; Octet16 p2; it = p2.begin(); it = std::copy(padding.begin(), padding.end(), it); it = std::copy(ia, ia + 6, it); it = std::copy(ra, ra + 6, it); for (uint8_t i = 0; i < OCTET16_LEN; i++) { p2[i] = p1bis[i] ^ p2[i]; } return aes_128(k, p2); } Octet16 s1(const Octet16& k, const Octet16& r1, const Octet16& r2) { Octet16 text{0}; constexpr uint8_t BT_OCTET8_LEN = 8; memcpy(text.data(), r1.data(), BT_OCTET8_LEN); memcpy(text.data() + BT_OCTET8_LEN, r2.data(), BT_OCTET8_LEN); return aes_128(k, text); } } // namespace crypto_toolbox } // namespace bluetooth No newline at end of file
system/gd/crypto_toolbox/crypto_toolbox.h +4 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,10 @@ namespace crypto_toolbox { constexpr int OCTET16_LEN = 16; using Octet16 = std::array<uint8_t, OCTET16_LEN>; Octet16 c1(const Octet16& k, const Octet16& r, const uint8_t* pres, const uint8_t* preq, const uint8_t iat, const uint8_t* ia, const uint8_t rat, const uint8_t* ra); Octet16 s1(const Octet16& k, const Octet16& r1, const Octet16& r2); extern Octet16 aes_128(const Octet16& key, const Octet16& message); extern Octet16 aes_cmac(const Octet16& key, const uint8_t* message, uint16_t length); extern Octet16 f4(uint8_t* u, uint8_t* v, const Octet16& x, uint8_t z); Loading
system/gd/hci/hci_layer.cc +4 −4 Original line number Diff line number Diff line Loading @@ -441,7 +441,7 @@ void HciLayer::UnregisterLeEventHandler(SubeventCode subevent_code) { impl_->UnregisterLeEventHandler(subevent_code); } const SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler) { for (const auto event : SecurityInterface::SecurityEvents) { RegisterEventHandler(event, event_handler, handler); Loading @@ -449,7 +449,7 @@ const SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(Ev return &impl_->security_interface; } const LeSecurityInterface* HciLayer::GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, LeSecurityInterface* HciLayer::GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, os::Handler* handler) { for (const auto subevent : LeSecurityInterface::LeSecurityEvents) { RegisterLeEventHandler(subevent, event_handler, handler); Loading
system/gd/hci/hci_layer.h +3 −4 Original line number Diff line number Diff line Loading @@ -57,10 +57,9 @@ class HciLayer : public Module { virtual void UnregisterLeEventHandler(SubeventCode subevent_code); const SecurityInterface* GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler); SecurityInterface* GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler); const LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, os::Handler* handler); static const ModuleFactory Factory; Loading
system/gd/hci/hci_packets.pdl +6 −2 Original line number Diff line number Diff line Loading @@ -2177,11 +2177,15 @@ packet LeRandComplete : CommandComplete (command_op_code = LE_RAND) { } packet LeStartEncryption : LeSecurityCommand (op_code = LE_START_ENCRYPTION) { _payload_, // placeholder (unimplemented) connection_handle: 16, rand: 8[8], ediv: 16, ltk: 8[16], } packet LeLongTermKeyRequestReply : LeSecurityCommand (op_code = LE_LONG_TERM_KEY_REQUEST_REPLY) { _payload_, // placeholder (unimplemented) connection_handle: 16, long_term_key: 8[16], } packet LeLongTermKeyRequestNegativeReply : LeSecurityCommand (op_code = LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY) { Loading