QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 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 "net/third_party/quiche/src/quic/core/crypto/aes_base_encrypter.h" |
| 6 | |
| 7 | #include "third_party/boringssl/src/include/openssl/aes.h" |
| 8 | #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h" |
| 9 | |
| 10 | namespace quic { |
| 11 | |
| 12 | bool AesBaseEncrypter::SetHeaderProtectionKey(QuicStringPiece key) { |
| 13 | if (key.size() != GetKeySize()) { |
| 14 | QUIC_BUG << "Invalid key size for header protection"; |
| 15 | return false; |
| 16 | } |
| 17 | if (AES_set_encrypt_key(reinterpret_cast<const uint8_t*>(key.data()), |
| 18 | key.size() * 8, &pne_key_) != 0) { |
| 19 | QUIC_BUG << "Unexpected failure of AES_set_encrypt_key"; |
| 20 | return false; |
| 21 | } |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | std::string AesBaseEncrypter::GenerateHeaderProtectionMask( |
| 26 | QuicStringPiece sample) { |
| 27 | if (sample.size() != AES_BLOCK_SIZE) { |
| 28 | return std::string(); |
| 29 | } |
| 30 | std::string out(AES_BLOCK_SIZE, 0); |
| 31 | AES_encrypt(reinterpret_cast<const uint8_t*>(sample.data()), |
| 32 | reinterpret_cast<uint8_t*>(const_cast<char*>(out.data())), |
| 33 | &pne_key_); |
| 34 | return out; |
| 35 | } |
| 36 | |
| 37 | } // namespace quic |