Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / net / quic / crypto / aes_128_gcm_12_encrypter_nss.cc
blobbc9b519eab8304d46e00f7b4e0788b7b37d64fb7
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.
5 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
7 #include <pk11pub.h>
8 #include <secerr.h>
10 #include "crypto/aes_128_gcm_helpers_nss.h"
12 using base::StringPiece;
14 namespace net {
16 namespace {
18 const size_t kKeySize = 16;
19 const size_t kNoncePrefixSize = 4;
21 SECStatus My_Encrypt(PK11SymKey* key,
22 CK_MECHANISM_TYPE mechanism,
23 SECItem* param,
24 unsigned char* out,
25 unsigned int* out_len,
26 unsigned int max_len,
27 const unsigned char* data,
28 unsigned int data_len) {
29 return crypto::PK11EncryptHelper(key, mechanism, param, out, out_len, max_len,
30 data, data_len);
33 } // namespace
35 Aes128Gcm12Encrypter::Aes128Gcm12Encrypter()
36 : AeadBaseEncrypter(CKM_AES_GCM, My_Encrypt, kKeySize, kAuthTagSize,
37 kNoncePrefixSize) {
38 static_assert(kKeySize <= kMaxKeySize, "key size too big");
39 static_assert(kNoncePrefixSize <= kMaxNoncePrefixSize,
40 "nonce prefix size too big");
43 Aes128Gcm12Encrypter::~Aes128Gcm12Encrypter() {}
45 void Aes128Gcm12Encrypter::FillAeadParams(StringPiece nonce,
46 StringPiece associated_data,
47 size_t auth_tag_size,
48 AeadParams* aead_params) const {
49 aead_params->len = sizeof(aead_params->data.gcm_params);
50 CK_GCM_PARAMS* gcm_params = &aead_params->data.gcm_params;
51 gcm_params->pIv =
52 reinterpret_cast<CK_BYTE*>(const_cast<char*>(nonce.data()));
53 gcm_params->ulIvLen = nonce.size();
54 gcm_params->pAAD =
55 reinterpret_cast<CK_BYTE*>(const_cast<char*>(associated_data.data()));
56 gcm_params->ulAADLen = associated_data.size();
57 gcm_params->ulTagBits = auth_tag_size * 8;
60 } // namespace net