| 130 | } |
| 131 | |
| 132 | bool EncyrptBuffer( |
| 133 | uint8 *m_buffer, |
| 134 | uint8 m_length, |
| 135 | Driver *driver, |
| 136 | uint8 const _sendingNode, |
| 137 | uint8 const _receivingNode, |
| 138 | uint8 const m_nonce[8], |
| 139 | uint8* e_buffer |
| 140 | ) |
| 141 | { |
| 142 | |
| 143 | #if 0 |
| 144 | m_nonce[0] = 0x09; |
| 145 | m_nonce[1] = 0x0d; |
| 146 | m_nonce[2] = 0x93; |
| 147 | m_nonce[3] = 0xd3; |
| 148 | m_nonce[4] = 0x61; |
| 149 | m_nonce[5] = 0x61; |
| 150 | m_nonce[6] = 0x1d; |
| 151 | m_nonce[7] = 0xd6; |
| 152 | #endif |
| 153 | uint8 len = 0; |
| 154 | e_buffer[len++] = SOF; |
| 155 | e_buffer[len++] = m_length + 18; // length of full packet |
| 156 | e_buffer[len++] = REQUEST; |
| 157 | e_buffer[len++] = FUNC_ID_ZW_SEND_DATA; |
| 158 | e_buffer[len++] = _receivingNode; |
| 159 | e_buffer[len++] = m_length + 11; // Length of the payload |
| 160 | e_buffer[len++] = Security::StaticGetCommandClassId(); |
| 161 | e_buffer[len++] = SecurityCmd_MessageEncap; |
| 162 | |
| 163 | /* create our IV */ |
| 164 | uint8 initializationVector[16]; |
| 165 | /* the first 8 bytes of a outgoing IV are random |
| 166 | * and we add it also to the start of the payload |
| 167 | */ |
| 168 | for (int i = 0; i < 8; i++) { |
| 169 | initializationVector[i] = (uint8) (255.0 * rand() / (RAND_MAX + 1.0)); |
| 170 | e_buffer[len++] = initializationVector[i]; |
| 171 | } |
| 172 | /* the remaining 8 bytes are the NONCE we got from the device */ |
| 173 | for (int i = 0; i < 8; i++) { |
| 174 | initializationVector[8+i] = m_nonce[i]; |
| 175 | } |
| 176 | |
| 177 | /* we need a copy b/c aes_ofb_encrypt will overwrite it */ |
| 178 | uint8 iv_dup[16]; |
| 179 | for (int i = 0; i < 16; i++) { |
| 180 | iv_dup[i] = initializationVector[i]; |
| 181 | } |
| 182 | |
| 183 | uint8 plaintextmsg[32]; |
| 184 | /* add the Sequence Flag |
| 185 | * - Since we dont currently handle multipacket encryption |
| 186 | * just set this to 0 |
| 187 | */ |
| 188 | plaintextmsg[0] = 0; |
| 189 | /* now add the actual message to be encrypted */ |
no test coverage detected