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

Side by Side Diff: net/quic/crypto/aead_base_decrypter.h

Issue 189893002: Add ChaCha20Poly1305Encrypter, based on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Move GCM-specific code back to the Aes128Gcm12En/Decrypter classes Created 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ 5 #ifndef NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_
6 #define NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ 6 #define NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_
7
8 #include <string>
9 7
10 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
11 #include "net/quic/crypto/quic_decrypter.h" 9 #include "net/quic/crypto/quic_decrypter.h"
12 10
13 #if defined(USE_OPENSSL) 11 #if defined(USE_OPENSSL)
14 #include "net/quic/crypto/scoped_evp_aead_ctx.h" 12 #include "net/quic/crypto/scoped_evp_aead_ctx.h"
13 #else
14 #include <pkcs11t.h>
15 #include <seccomon.h>
16 typedef struct PK11SymKeyStr PK11SymKey;
17 typedef SECStatus (*PK11_DecryptFunction)(
18 PK11SymKey* symKey, CK_MECHANISM_TYPE mechanism, SECItem* param,
19 unsigned char* out, unsigned int* outLen, unsigned int maxLen,
20 const unsigned char* enc, unsigned encLen);
15 #endif 21 #endif
16 22
17 namespace net { 23 namespace net {
18 24
19 namespace test { 25 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses.
20 class Aes128Gcm12DecrypterPeer; 26 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter {
21 } // namespace test
22
23 // An Aes128Gcm12Decrypter is a QuicDecrypter that implements the
24 // AEAD_AES_128_GCM_12 algorithm specified in RFC 5282. Create an instance by
25 // calling QuicDecrypter::Create(kAESG).
26 //
27 // It uses an authentication tag of 12 bytes (96 bits). The fixed prefix
28 // of the nonce is four bytes.
29 class NET_EXPORT_PRIVATE Aes128Gcm12Decrypter : public QuicDecrypter {
30 public: 27 public:
31 enum { 28 #if defined(USE_OPENSSL)
32 // Authentication tags are truncated to 96 bits. 29 AeadBaseDecrypter(const EVP_AEAD* aead_alg,
33 kAuthTagSize = 12, 30 size_t key_size,
34 }; 31 size_t auth_tag_size,
35 32 size_t nonce_prefix_size);
36 Aes128Gcm12Decrypter(); 33 #else
37 virtual ~Aes128Gcm12Decrypter(); 34 AeadBaseDecrypter(CK_MECHANISM_TYPE aead_mechanism,
38 35 PK11_DecryptFunction pk11_decrypt,
39 // Returns true if the underlying crypto library supports AES GCM. 36 size_t key_size,
40 static bool IsSupported(); 37 size_t auth_tag_size,
38 size_t nonce_prefix_size);
39 #endif
40 virtual ~AeadBaseDecrypter();
41 41
42 // QuicDecrypter implementation 42 // QuicDecrypter implementation
43 virtual bool SetKey(base::StringPiece key) OVERRIDE; 43 virtual bool SetKey(base::StringPiece key) OVERRIDE;
44 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) OVERRIDE; 44 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) OVERRIDE;
45 virtual bool Decrypt(base::StringPiece nonce, 45 virtual bool Decrypt(base::StringPiece nonce,
46 base::StringPiece associated_data, 46 base::StringPiece associated_data,
47 base::StringPiece ciphertext, 47 base::StringPiece ciphertext,
48 unsigned char* output, 48 unsigned char* output,
49 size_t* output_length) OVERRIDE; 49 size_t* output_length) OVERRIDE;
50 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number, 50 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number,
51 base::StringPiece associated_data, 51 base::StringPiece associated_data,
52 base::StringPiece ciphertext) OVERRIDE; 52 base::StringPiece ciphertext) OVERRIDE;
53 virtual base::StringPiece GetKey() const OVERRIDE; 53 virtual base::StringPiece GetKey() const OVERRIDE;
54 virtual base::StringPiece GetNoncePrefix() const OVERRIDE; 54 virtual base::StringPiece GetNoncePrefix() const OVERRIDE;
55 55
56 protected:
57 // Make these constants available to the subclasses so that the subclasses
58 // can assert at compile time their key_size_ and nonce_prefix_size_ do not
59 // exceed the maximum.
60 static const size_t kMaxKeySize = 32;
61 static const size_t kMaxNoncePrefixSize = 4;
62
63 #if !defined(USE_OPENSSL)
64 struct AeadParams {
65 unsigned int len;
66 union {
67 CK_GCM_PARAMS gcm_params;
68 #if !defined(USE_NSS)
69 // USE_NSS means we are using system NSS rather than our copy of NSS.
70 // The system NSS <pkcs11n.h> header doesn't define this type yet.
71 CK_NSS_AEAD_PARAMS nss_aead_params;
72 #endif
73 } data;
74 };
75
76 virtual void FillAeadParams(base::StringPiece nonce,
77 base::StringPiece associated_data,
78 size_t auth_tag_size,
79 AeadParams* aead_params) const = 0;
80 #endif // !defined(USE_OPENSSL)
81
56 private: 82 private:
57 // The 128-bit AES key. 83 #if defined(USE_OPENSSL)
58 unsigned char key_[16]; 84 const EVP_AEAD* aead_alg_;
wtc 2014/03/11 04:21:12 Note to self: make this member const: const EVP
85 #else
86 CK_MECHANISM_TYPE aead_mechanism_;
wtc 2014/03/11 04:21:12 Note to self: make this member const.
87 const PK11_DecryptFunction pk11_decrypt_;
wtc 2014/03/11 15:53:50 I just realized that pk11_decrypt_ is essentially
88 #endif
89 const size_t key_size_;
90 const size_t auth_tag_size_;
91 const size_t nonce_prefix_size_;
92
93 // The key.
94 unsigned char key_[kMaxKeySize];
59 // The nonce prefix. 95 // The nonce prefix.
60 unsigned char nonce_prefix_[4]; 96 unsigned char nonce_prefix_[kMaxNoncePrefixSize];
61 97
62 #if defined(USE_OPENSSL) 98 #if defined(USE_OPENSSL)
63 ScopedEVPAEADCtx ctx_; 99 ScopedEVPAEADCtx ctx_;
64 #endif 100 #endif
65 }; 101 };
66 102
67 } // namespace net 103 } // namespace net
68 104
69 #endif // NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ 105 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698