| 179 | |
| 180 | |
| 181 | bool EmeCryptContext::init(const BYTE *key, bool hkdf, CryptConfig *pConfig) |
| 182 | { |
| 183 | const BYTE *emeKey = key; |
| 184 | |
| 185 | if (!pConfig) |
| 186 | throw std::exception("EMeCryptContext init: where is my config?"); |
| 187 | |
| 188 | LockZeroBuffer<BYTE> hkdfKey(MASTER_KEY_LEN, false); |
| 189 | |
| 190 | if (hkdf) { |
| 191 | if (!hkdfKey.IsLocked()) |
| 192 | return false; |
| 193 | if (!hkdfDerive(key, MASTER_KEY_LEN, hkdfKey.m_buf, hkdfKey.m_len, hkdfInfoEMENames)) |
| 194 | return false; |
| 195 | |
| 196 | emeKey = hkdfKey.m_buf; |
| 197 | } |
| 198 | |
| 199 | m_pKeyBuf = new LockZeroBuffer<AES_KEY>(2, true); |
| 200 | |
| 201 | pConfig->m_keybuf_manager.RegisterBuf(m_pKeyBuf); |
| 202 | |
| 203 | AES::initialize_keys(emeKey, 256, &m_pKeyBuf->m_buf[0], &m_pKeyBuf->m_buf[1]); |
| 204 | |
| 205 | m_aes_ctx.set_keys(&m_pKeyBuf->m_buf[0], &m_pKeyBuf->m_buf[1]); |
| 206 | |
| 207 | tabulateL(16 * 8, pConfig); |
| 208 | |
| 209 | return true; |
| 210 | |
| 211 | } |
| 212 | |
| 213 | |
| 214 |
no test coverage detected