mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-10-30 22:56:22 +00:00
[TAS-108] first implementation of verify_dsm_pkr()
* osnma_msg_receiver : leafs computation without loop and root comparison * gnss_crypto : getMerkleRoot() to return d_x_4_0
This commit is contained in:
parent
ba357ebd9c
commit
d01ea978c6
@ -416,8 +416,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector<uint8_t>& dsm_msg
|
|||||||
<< ", TOW=" << static_cast<uint32_t>(d_osnma_data.d_dsm_kroot_message.towh_k) * 3600
|
<< ", TOW=" << static_cast<uint32_t>(d_osnma_data.d_dsm_kroot_message.towh_k) * 3600
|
||||||
<< " received" << std::endl;
|
<< " received" << std::endl;
|
||||||
// C: NPK verification against Merkle tree root.
|
// C: NPK verification against Merkle tree root.
|
||||||
std::vector<uint8_t> m_0;
|
d_public_key_verified = verify_dsm_pkr(d_osnma_data.d_dsm_pkr_message);
|
||||||
d_public_key_verified = verify_dsm_pkr(d_osnma_data.d_dsm_pkr_message, m_0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -735,10 +734,49 @@ void osnma_msg_receiver::process_mack_message(const std::shared_ptr<OSNMA_msg>&
|
|||||||
// C: TODO - where m = (PRNd || PRNa || GSTsf || CTR || NMAS || NavData || P)
|
// C: TODO - where m = (PRNd || PRNa || GSTsf || CTR || NMAS || NavData || P)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool osnma_msg_receiver::verify_dsm_pkr(DSM_PKR_message message, std::vector<uint8_t> m0)
|
bool osnma_msg_receiver::verify_dsm_pkr(DSM_PKR_message message)
|
||||||
{
|
{
|
||||||
// TODO concatenate message
|
// TODO create leafe base message m_i
|
||||||
// TODO create function for recursively apply hash
|
// TODO create function for recursively apply hash
|
||||||
|
|
||||||
|
// build base leaf m_i
|
||||||
|
// auto leaf = message.mid;
|
||||||
|
std::vector<uint8_t> m_i;
|
||||||
|
m_i.reserve(2 + message.npk.size());
|
||||||
|
m_i[0] = message.npkt;
|
||||||
|
m_i[1] = message.npktid;
|
||||||
|
for (uint8_t i = 2; i < m_i.size(); i++)
|
||||||
|
{
|
||||||
|
m_i.push_back(message.npk[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute intermediate leafs' values
|
||||||
|
std::vector<uint8_t> x_0,x_1,x_2,x_3,x_4;
|
||||||
|
// uint8_t k = 0;
|
||||||
|
x_0 = d_crypto->computeSHA256(m_i);
|
||||||
|
x_0.insert(x_0.end(),message.itn.begin(),&message.itn[31]);
|
||||||
|
x_1 = d_crypto->computeSHA256(x_0);
|
||||||
|
x_1.insert(x_1.end(),&message.itn[32],&message.itn[63]);
|
||||||
|
x_2 = d_crypto->computeSHA256(x_1);
|
||||||
|
x_2.insert(x_2.end(),&message.itn[64],&message.itn[95]);
|
||||||
|
x_3 = d_crypto->computeSHA256(x_2);
|
||||||
|
x_3.insert(x_3.end(),&message.itn[96],&message.itn[127]);
|
||||||
|
// root leaf computation
|
||||||
|
x_4 = d_crypto->computeSHA256(x_3);
|
||||||
|
|
||||||
|
// C: d_crypto->getMerkleRoot([m_0:m_15]) I realised I could have done this...
|
||||||
|
// C: ... but why computing all the possible results? I have only one leaf in each osnma message...
|
||||||
|
// verify that computed root matches merkle root
|
||||||
|
|
||||||
|
if(x_4 == d_crypto->getMerkleRoot())
|
||||||
|
{
|
||||||
|
std::cout << "Galileo OSNMA: DSM-PKR verified successfully! " << std::endl;
|
||||||
|
return true;
|
||||||
|
// C: NPK verification against Merkle tree root.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Galileo OSNMA: DSM-PKR verification unsuccessful !" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ private:
|
|||||||
void read_dsm_header(uint8_t dsm_header);
|
void read_dsm_header(uint8_t dsm_header);
|
||||||
void read_dsm_block(const std::shared_ptr<OSNMA_msg>& osnma_msg);
|
void read_dsm_block(const std::shared_ptr<OSNMA_msg>& osnma_msg);
|
||||||
void process_dsm_message(const std::vector<uint8_t>& dsm_msg, const std::shared_ptr<OSNMA_msg>& osnma_msg);
|
void process_dsm_message(const std::vector<uint8_t>& dsm_msg, const std::shared_ptr<OSNMA_msg>& osnma_msg);
|
||||||
bool verify_dsm_pkr(DSM_PKR_message message, std::vector<uint8_t> input_message);
|
bool verify_dsm_pkr(DSM_PKR_message message);
|
||||||
void read_mack_block(const std::shared_ptr<OSNMA_msg>& osnma_msg);
|
void read_mack_block(const std::shared_ptr<OSNMA_msg>& osnma_msg);
|
||||||
void read_mack_header();
|
void read_mack_header();
|
||||||
void read_mack_body();
|
void read_mack_body();
|
||||||
|
@ -50,6 +50,10 @@ public:
|
|||||||
void readPublicKeyFromPEM(const std::string& pemFilePath);
|
void readPublicKeyFromPEM(const std::string& pemFilePath);
|
||||||
void read_merkle_xml(const std::string& merkleFilePath);
|
void read_merkle_xml(const std::string& merkleFilePath);
|
||||||
std::vector<uint8_t> getMerkleRoot(const std::vector<std::vector<uint8_t>>& merkle) const;
|
std::vector<uint8_t> getMerkleRoot(const std::vector<std::vector<uint8_t>>& merkle) const;
|
||||||
|
std::vector<uint8_t> getMerkleRoot() const
|
||||||
|
{
|
||||||
|
return d_x_4_0;
|
||||||
|
}
|
||||||
|
|
||||||
// void set_public_key(const std::vector<uint8_t>& publickey);
|
// void set_public_key(const std::vector<uint8_t>& publickey);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user