26 const bool extended_master_secret = state->
server_hello()->supports_extended_master_secret();
28 const size_t prf_gen = 2 * (mac_keylen + cipher_keylen + cipher_nonce_bytes);
30 const uint8_t MASTER_SECRET_MAGIC[] = {0x6D, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74};
32 const uint8_t EXT_MASTER_SECRET_MAGIC[] = {0x65, 0x78, 0x74, 0x65, 0x6E, 0x64, 0x65, 0x64, 0x20, 0x6D, 0x61,
33 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74};
35 const uint8_t KEY_GEN_MAGIC[] = {0x6B, 0x65, 0x79, 0x20, 0x65, 0x78, 0x70, 0x61, 0x6E, 0x73, 0x69, 0x6F, 0x6E};
41 m_master_sec = pre_master_secret;
43 std::vector<uint8_t> salt;
44 std::vector<uint8_t> label;
45 if(extended_master_secret) {
46 label.assign(EXT_MASTER_SECRET_MAGIC, EXT_MASTER_SECRET_MAGIC +
sizeof(EXT_MASTER_SECRET_MAGIC));
49 label.assign(MASTER_SECRET_MAGIC, MASTER_SECRET_MAGIC +
sizeof(MASTER_SECRET_MAGIC));
54 m_master_sec = prf->derive_key(48, pre_master_secret, salt, label);
57 std::vector<uint8_t> salt;
58 std::vector<uint8_t> label;
59 label.assign(KEY_GEN_MAGIC, KEY_GEN_MAGIC +
sizeof(KEY_GEN_MAGIC));
64 prf_gen, m_master_sec.data(), m_master_sec.size(), salt.data(), salt.size(), label.data(), label.size());
66 const uint8_t* key_data = prf_output.data();
68 m_c_aead.resize(mac_keylen + cipher_keylen);
69 m_s_aead.resize(mac_keylen + cipher_keylen);
71 copy_mem(&m_c_aead[0], key_data, mac_keylen);
72 copy_mem(&m_s_aead[0], key_data + mac_keylen, mac_keylen);
74 copy_mem(&m_c_aead[mac_keylen], key_data + 2 * mac_keylen, cipher_keylen);
75 copy_mem(&m_s_aead[mac_keylen], key_data + 2 * mac_keylen + cipher_keylen, cipher_keylen);
77 m_c_nonce.resize(cipher_nonce_bytes);
78 m_s_nonce.resize(cipher_nonce_bytes);
80 copy_mem(&m_c_nonce[0], key_data + 2 * (mac_keylen + cipher_keylen), cipher_nonce_bytes);
81 copy_mem(&m_s_nonce[0], key_data + 2 * (mac_keylen + cipher_keylen) + cipher_nonce_bytes, cipher_nonce_bytes);