30 const size_t cipher_keylen = suite.cipher_keylen();
31 const size_t mac_keylen = suite.mac_keylen();
32 const size_t cipher_nonce_bytes = suite.nonce_bytes_from_handshake();
34 const bool extended_master_secret = state->
server_hello()->supports_extended_master_secret();
36 const size_t prf_gen = 2 * (mac_keylen + cipher_keylen + cipher_nonce_bytes);
38 const uint8_t MASTER_SECRET_MAGIC[] = {0x6D, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74};
40 const uint8_t EXT_MASTER_SECRET_MAGIC[] = {0x65, 0x78, 0x74, 0x65, 0x6E, 0x64, 0x65, 0x64, 0x20, 0x6D, 0x61,
41 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74};
43 const uint8_t KEY_GEN_MAGIC[] = {0x6B, 0x65, 0x79, 0x20, 0x65, 0x78, 0x70, 0x61, 0x6E, 0x73, 0x69, 0x6F, 0x6E};
49 m_master_sec = pre_master_secret;
51 std::vector<uint8_t> salt;
52 std::vector<uint8_t> label;
53 if(extended_master_secret) {
54 label.assign(EXT_MASTER_SECRET_MAGIC, EXT_MASTER_SECRET_MAGIC +
sizeof(EXT_MASTER_SECRET_MAGIC));
55 salt += state->
hash().
final(suite.prf_algo());
57 label.assign(MASTER_SECRET_MAGIC, MASTER_SECRET_MAGIC +
sizeof(MASTER_SECRET_MAGIC));
62 m_master_sec = prf->derive_key(48, pre_master_secret, salt, label);
65 std::vector<uint8_t> salt;
66 std::vector<uint8_t> label;
67 label.assign(KEY_GEN_MAGIC, KEY_GEN_MAGIC +
sizeof(KEY_GEN_MAGIC));
72 prf_gen, m_master_sec.data(), m_master_sec.size(), salt.data(), salt.size(), label.data(), label.size());
74 const uint8_t* key_data = prf_output.data();
76 m_c_aead.resize(mac_keylen + cipher_keylen);
77 m_s_aead.resize(mac_keylen + cipher_keylen);
80 copy_mem(&m_c_aead[0], key_data, mac_keylen);
81 copy_mem(&m_s_aead[0], key_data + mac_keylen, mac_keylen);
85 if(cipher_keylen > 0) {
86 copy_mem(&m_c_aead[mac_keylen], key_data + 2 * mac_keylen, cipher_keylen);
87 copy_mem(&m_s_aead[mac_keylen], key_data + 2 * mac_keylen + cipher_keylen, cipher_keylen);
93 if(cipher_nonce_bytes > 0) {
94 const uint8_t* c_nonce_bytes = key_data + 2 * (mac_keylen + cipher_keylen);
95 m_c_nonce.assign(c_nonce_bytes, c_nonce_bytes + cipher_nonce_bytes);
97 const uint8_t* s_nonce_bytes = key_data + 2 * (mac_keylen + cipher_keylen) + cipher_nonce_bytes;
98 m_s_nonce.assign(s_nonce_bytes, s_nonce_bytes + cipher_nonce_bytes);