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"
10 #include "crypto/aes_128_gcm_helpers_nss.h"
12 using base::StringPiece
;
18 const size_t kKeySize
= 16;
19 const size_t kNoncePrefixSize
= 4;
21 SECStatus
My_Encrypt(PK11SymKey
* key
,
22 CK_MECHANISM_TYPE mechanism
,
25 unsigned int* out_len
,
27 const unsigned char* data
,
28 unsigned int data_len
) {
29 return crypto::PK11EncryptHelper(key
, mechanism
, param
, out
, out_len
, max_len
,
35 Aes128Gcm12Encrypter::Aes128Gcm12Encrypter()
36 : AeadBaseEncrypter(CKM_AES_GCM
, My_Encrypt
, kKeySize
, kAuthTagSize
,
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
,
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
;
52 reinterpret_cast<CK_BYTE
*>(const_cast<char*>(nonce
.data()));
53 gcm_params
->ulIvLen
= nonce
.size();
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;