MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / GenerateNonceKey

Method GenerateNonceKey

cpp/src/Node.cpp:3766–3800  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Generate a NONCE key for this node -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

3764// Generate a NONCE key for this node
3765//-----------------------------------------------------------------------------
3766uint8 *Node::GenerateNonceKey() {
3767 uint8 idx = this->m_lastnonce;
3768
3769 /* The first byte must be unique and non-zero. The others are random.
3770 Per Numerical Recipes in C its best to use the high-order byte. The
3771 floating point calculation here doesn't assume the size of the random
3772 integer, otherwise we could just shift the high byte over.
3773 */
3774 uint8 match = 0;
3775 do {
3776 this->m_nonces[idx][0] = 1 + (uint8) (255.0 * rand() / (RAND_MAX + 1.0));
3777 match = 0;
3778 for (int i = 0; i < 8; i++) {
3779 if (i == idx) {
3780 continue;
3781 }
3782 if (this->m_nonces[idx][0] == this->m_nonces[i][0]) {
3783 match = 1;
3784 }
3785 }
3786 } while (match);
3787
3788 /* The other bytes have no restrictions. */
3789 for (int i = 1; i < 8; i++) {
3790 this->m_nonces[idx][i] = (int) (256.0 * rand() / (RAND_MAX + 1.0));
3791 }
3792
3793 this->m_lastnonce++;
3794 if (this->m_lastnonce >= 8)
3795 this->m_lastnonce = 0;
3796 for (uint8 i = 0; i < 8; i++) {
3797 PrintHex("NONCES", (const uint8_t*)this->m_nonces[i], 8);
3798 }
3799 return &this->m_nonces[idx][0];
3800}
3801//-----------------------------------------------------------------------------
3802// <Node::GetNonceKey>
3803// Get a NONCE key for this node that matches the nonceid.

Callers 2

WriteMsgMethod · 0.80
ProcessMsgMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected