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

Method initNetworkKeys

cpp/src/Driver.cpp:7088–7150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7086}
7087
7088bool Driver::initNetworkKeys(bool newnode) {
7089
7090 uint8_t EncryptPassword[16] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
7091 uint8_t AuthPassword[16] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
7092
7093 uint8_t SecuritySchemes[1][16] = {
7094 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
7095 };
7096 this->m_inclusionkeySet = newnode;
7097 this->AuthKey = new aes_encrypt_ctx;
7098 this->EncryptKey = new aes_encrypt_ctx;
7099
7100 Log::Write(LogLevel_Info, GetControllerNodeId(), "Setting Up %s Network Key for Secure Communications", newnode == true ? "Inclusion" : "Provided");
7101
7102 if (!isNetworkKeySet()) {
7103 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed - Network Key Not Set");
7104 return false;
7105 }
7106
7107 if (aes_init() == EXIT_FAILURE) {
7108 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to Init AES Engine");
7109 return false;
7110 }
7111
7112 if (aes_encrypt_key128(newnode == false ? this->GetNetworkKey() : SecuritySchemes[0], this->EncryptKey) == EXIT_FAILURE) {
7113 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to Set Initial Network Key for Encryption");
7114 return false;
7115 }
7116
7117 if (aes_encrypt_key128(newnode == false ? this->GetNetworkKey() : SecuritySchemes[0], this->AuthKey) == EXIT_FAILURE) {
7118 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to Set Initial Network Key for Authentication");
7119 return false;
7120 }
7121
7122 uint8 tmpEncKey[32];
7123 uint8 tmpAuthKey[32];
7124 aes_mode_reset(this->EncryptKey);
7125 aes_mode_reset(this->AuthKey);
7126
7127 if (aes_ecb_encrypt(EncryptPassword, tmpEncKey, 16, this->EncryptKey) == EXIT_FAILURE) {
7128 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to Generate Encrypted Network Key for Encryption");
7129 return false;
7130 }
7131 if (aes_ecb_encrypt(AuthPassword, tmpAuthKey, 16, this->AuthKey) == EXIT_FAILURE) {
7132 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to Generate Encrypted Network Key for Authentication");
7133 return false;
7134 }
7135
7136
7137 aes_mode_reset(this->EncryptKey);
7138 aes_mode_reset(this->AuthKey);
7139 if (aes_encrypt_key128(tmpEncKey, this->EncryptKey) == EXIT_FAILURE) {
7140 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to set Encrypted Network Key for Encryption");
7141 return false;
7142 }
7143 if (aes_encrypt_key128(tmpAuthKey, this->AuthKey) == EXIT_FAILURE) {
7144 Log::Write(LogLevel_Warning, GetControllerNodeId(), "Failed to set Encrypted Network Key for Authentication");
7145 return false;

Callers

nothing calls this directly

Calls 6

GetNetworkKeyMethod · 0.95
WriteFunction · 0.85
GetControllerNodeIdFunction · 0.85
aes_initFunction · 0.85
aes_mode_resetFunction · 0.85
aes_ecb_encryptFunction · 0.85

Tested by

no test coverage detected