blob: 6888ab22f6c5e6d823d4e85e46e74fc0753b1d7f [file] [log] [blame]
QUICHE team2d187972019-03-19 16:23:47 -07001// 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_decrypter.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
10namespace quic {
11
12bool AesBaseDecrypter::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
25std::string AesBaseDecrypter::GenerateHeaderProtectionMask(
26 QuicDataReader* sample_reader) {
27 QuicStringPiece sample;
28 if (!sample_reader->ReadStringPiece(&sample, AES_BLOCK_SIZE)) {
29 return std::string();
30 }
31 std::string out(AES_BLOCK_SIZE, 0);
32 AES_encrypt(reinterpret_cast<const uint8_t*>(sample.data()),
33 reinterpret_cast<uint8_t*>(const_cast<char*>(out.data())),
34 &pne_key_);
35 return out;
36}
37
38} // namespace quic