Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: net/quic/crypto/aes_128_gcm_encrypter_nss.cc

Issue 12623017: Add Aes128GcmEncrypter and Aes128GcmDecrypter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add a stub NSS-based implementation. Skip tests if AES GCM is not supported. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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/quic/crypto/aes_128_gcm_encrypter.h"
6
7 #include <string.h>
8
9 #include "base/memory/scoped_ptr.h"
10
11 using base::StringPiece;
12
13 namespace net {
14
15 namespace {
16
17 const size_t kKeySize = 16;
18 const size_t kNoncePrefixSize = 4;
19 const size_t kAuthTagSize = 16;
20
21 } // namespace
22
23 // static
24 bool Aes128GcmEncrypter::IsSupported() {
25 return false;
26 }
27
28 bool Aes128GcmEncrypter::SetKey(StringPiece key) {
29 if (key.size() != sizeof(key_)) {
30 return false;
31 }
32 memcpy(key_, key.data(), key.size());
33 return true;
34 }
35
36 bool Aes128GcmEncrypter::SetNoncePrefix(StringPiece nonce_prefix) {
37 if (nonce_prefix.size() != kNoncePrefixSize) {
38 return false;
39 }
40 memcpy(nonce_, nonce_prefix.data(), nonce_prefix.size());
41 return true;
42 }
43
44 QuicData* Aes128GcmEncrypter::Encrypt(QuicPacketSequenceNumber sequence_number,
45 StringPiece associated_data,
46 StringPiece plaintext) {
47 COMPILE_ASSERT(sizeof(nonce_) == kNoncePrefixSize + sizeof(sequence_number),
48 incorrect_nonce_size);
49 memcpy(nonce_ + kNoncePrefixSize, &sequence_number, sizeof(sequence_number));
50 return EncryptWithNonce(StringPiece(reinterpret_cast<char*>(nonce_),
51 sizeof(nonce_)),
52 associated_data, plaintext);
53 }
54
55 size_t Aes128GcmEncrypter::GetKeySize() const {
56 return kKeySize;
57 }
58
59 size_t Aes128GcmEncrypter::GetNoncePrefixSize() const {
60 return kNoncePrefixSize;
61 }
62
63 size_t Aes128GcmEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
64 return ciphertext_size - kAuthTagSize;
65 }
66
67 // An AEAD_AES_128_GCM ciphertext is exactly 16 bytes longer than its
68 // corresponding plaintext.
69 size_t Aes128GcmEncrypter::GetCiphertextSize(size_t plaintext_size) const {
70 return plaintext_size + kAuthTagSize;
71 }
72
73 QuicData* Aes128GcmEncrypter::EncryptWithNonce(StringPiece nonce,
74 StringPiece associated_data,
75 StringPiece plaintext) {
76 size_t ciphertext_size = GetCiphertextSize(plaintext.length());
77 scoped_ptr<char[]> ciphertext(new char[ciphertext_size]);
78
79 // TODO(wtc): implement this function using NSS.
80
81 return new QuicData(ciphertext.release(), ciphertext_size, true);
82 }
83
84 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698