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

Side by Side Diff: net/quic/crypto/aes_128_gcm_decrypter_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_decrypter.h"
6
7 #include "base/memory/scoped_ptr.h"
8
9 using base::StringPiece;
10
11 namespace net {
12
13 namespace {
14
15 const size_t kKeySize = 16;
16 const size_t kNoncePrefixSize = 4;
17 const size_t kAuthTagSize = 16;
18
19 } // namespace
20
21 // static
22 bool Aes128GcmDecrypter::IsSupported() {
23 return false;
24 }
25
26 bool Aes128GcmDecrypter::SetKey(StringPiece key) {
27 if (key.size() != sizeof(key_)) {
28 return false;
29 }
30 memcpy(key_, key.data(), key.size());
31 return true;
32 }
33
34 bool Aes128GcmDecrypter::SetNoncePrefix(StringPiece nonce_prefix) {
35 if (nonce_prefix.size() != kNoncePrefixSize) {
36 return false;
37 }
38 memcpy(nonce_, nonce_prefix.data(), nonce_prefix.size());
39 return true;
40 }
41
42 QuicData* Aes128GcmDecrypter::Decrypt(QuicPacketSequenceNumber sequence_number,
43 StringPiece associated_data,
44 StringPiece ciphertext) {
45 COMPILE_ASSERT(sizeof(nonce_) == kNoncePrefixSize + sizeof(sequence_number),
46 incorrect_nonce_size);
47 memcpy(nonce_ + kNoncePrefixSize, &sequence_number, sizeof(sequence_number));
48 return DecryptWithNonce(StringPiece(reinterpret_cast<char*>(nonce_),
49 sizeof(nonce_)),
50 associated_data, ciphertext);
51 }
52
53 QuicData* Aes128GcmDecrypter::DecryptWithNonce(StringPiece nonce,
54 StringPiece associated_data,
55 StringPiece ciphertext) {
56 if (ciphertext.length() < kAuthTagSize) {
57 return NULL;
58 }
59 size_t plaintext_size = ciphertext.length() - kAuthTagSize;
60 scoped_ptr<char[]> plaintext(new char[plaintext_size]);
61
62 // TODO(wtc): implement this function using NSS.
wtc 2013/03/13 19:08:07 Yes, we do. I added a stub implementation in this
63
64 return new QuicData(plaintext.release(), plaintext_size, true);
65 }
66
67 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698