blob: 49fc71d46029b4c9535680e2e1a555ae8b59293a [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_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
10namespace quic {
11
12bool 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
25std::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