OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/cryptauth/session_keys.h" |
| 6 |
| 7 #include "base/strings/string_piece.h" |
| 8 #include "crypto/hkdf.h" |
| 9 |
| 10 namespace cryptauth { |
| 11 namespace { |
| 12 |
| 13 // The salt used to compute the devired keys. SHA256 of "D2D". |
| 14 const uint8_t kSalt[] = {0x82, 0xAA, 0x55, 0xA0, 0xD3, 0x97, 0xF8, 0x83, |
| 15 0x46, 0xCA, 0x1C, 0xEE, 0x8D, 0x39, 0x09, 0xB9, |
| 16 0x5F, 0x13, 0xFA, 0x7D, 0xEB, 0x1D, 0x4A, 0xB3, |
| 17 0x83, 0x76, 0xB8, 0x25, 0x6D, 0xA8, 0x55, 0x10}; |
| 18 |
| 19 // The number of bytes in the derived keys. |
| 20 const int kKeySize = 32; |
| 21 |
| 22 // String used in the derivation of the inititor encoding key. |
| 23 const char kInitiatorPurpose[] = "initiator"; |
| 24 |
| 25 // String used in the derivation of the responder encoding key. |
| 26 const char kResponderPurpose[] = "responder"; |
| 27 |
| 28 } // namespace |
| 29 |
| 30 SessionKeys::SessionKeys(const std::string& master_symmetric_key) { |
| 31 std::string salt(reinterpret_cast<const char*>(&kSalt[0]), sizeof(kSalt)); |
| 32 |
| 33 // We set the key_length to the length of the expected output and then take |
| 34 // the result from the first key, which is the client write key. |
| 35 crypto::HKDF initiator_encode(master_symmetric_key, salt, kInitiatorPurpose, |
| 36 kKeySize, 0, 0); |
| 37 initiator_encode_key_ = initiator_encode.client_write_key().as_string(); |
| 38 |
| 39 crypto::HKDF responder_encode(master_symmetric_key, salt, kResponderPurpose, |
| 40 kKeySize, 0, 0); |
| 41 responder_encode_key_ = responder_encode.client_write_key().as_string(); |
| 42 } |
| 43 |
| 44 SessionKeys::SessionKeys() {} |
| 45 |
| 46 SessionKeys::~SessionKeys() {} |
| 47 |
| 48 std::string SessionKeys::initiator_encode_key() const { |
| 49 return initiator_encode_key_; |
| 50 } |
| 51 |
| 52 std::string SessionKeys::responder_encode_key() const { |
| 53 return responder_encode_key_; |
| 54 } |
| 55 |
| 56 } // namespace cryptauth |
OLD | NEW |