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

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: Fix build errors. Add GetKey and GetNoncePrefix. 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 DCHECK_EQ(key.size(), sizeof(key_));
28 if (key.size() != sizeof(key_)) {
29 return false;
30 }
31 memcpy(key_, key.data(), key.size());
32 return true;
33 }
34
35 bool Aes128GcmDecrypter::SetNoncePrefix(StringPiece nonce_prefix) {
36 DCHECK_EQ(nonce_prefix.size(), kNoncePrefixSize);
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* Aes128GcmDecrypter::Decrypt(QuicPacketSequenceNumber sequence_number,
45 StringPiece associated_data,
46 StringPiece ciphertext) {
47 COMPILE_ASSERT(sizeof(nonce_) == kNoncePrefixSize + sizeof(sequence_number),
48 incorrect_nonce_size);
49 memcpy(nonce_ + kNoncePrefixSize, &sequence_number, sizeof(sequence_number));
50 return DecryptWithNonce(StringPiece(reinterpret_cast<char*>(nonce_),
51 sizeof(nonce_)),
52 associated_data, ciphertext);
53 }
54
55 StringPiece Aes128GcmDecrypter::GetKey() const {
56 return StringPiece(reinterpret_cast<const char*>(key_), sizeof(key_));
57 }
58
59 StringPiece Aes128GcmDecrypter::GetNoncePrefix() const {
60 return StringPiece(reinterpret_cast<const char*>(nonce_), kNoncePrefixSize);
61 }
62
63 QuicData* Aes128GcmDecrypter::DecryptWithNonce(StringPiece nonce,
64 StringPiece associated_data,
65 StringPiece ciphertext) {
66 if (ciphertext.length() < kAuthTagSize) {
67 return NULL;
68 }
69 size_t plaintext_size = ciphertext.length() - kAuthTagSize;
70 scoped_ptr<char[]> plaintext(new char[plaintext_size]);
71
72 // TODO(wtc): implement this function using NSS.
73
74 return new QuicData(plaintext.release(), plaintext_size, true);
75 }
76
77 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698