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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
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 #ifndef NET_QUIC_CRYPTO_AEAD_BASE_ENCRYPTER_H_
6 #define NET_QUIC_CRYPTO_AEAD_BASE_ENCRYPTER_H_
7
8 #include "base/compiler_specific.h"
9 #include "net/quic/crypto/quic_encrypter.h"
10
11 #if defined(USE_OPENSSL)
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_EncryptFunction)(
18 PK11SymKey* symKey, CK_MECHANISM_TYPE mechanism, SECItem* param,
19 unsigned char* out, unsigned int* outLen, unsigned int maxLen,
20 const unsigned char* data, unsigned int dataLen);
21 #endif
22
23 namespace net {
24
25 // AeadBaseEncrypter is the base class of AEAD QuicEncrypter subclasses.
26 class NET_EXPORT_PRIVATE AeadBaseEncrypter : public QuicEncrypter {
27 public:
28 #if defined(USE_OPENSSL)
29 AeadBaseEncrypter(const EVP_AEAD* aead_alg,
30 size_t key_size,
31 size_t auth_tag_size,
32 size_t nonce_prefix_size);
33 #else
34 AeadBaseEncrypter(CK_MECHANISM_TYPE aead_mechanism,
35 PK11_EncryptFunction pk11_encrypt,
36 size_t key_size,
37 size_t auth_tag_size,
38 size_t nonce_prefix_size);
39 #endif
40 ~AeadBaseEncrypter() override;
41
42 // QuicEncrypter implementation
43 bool SetKey(base::StringPiece key) override;
44 bool SetNoncePrefix(base::StringPiece nonce_prefix) override;
45 bool Encrypt(base::StringPiece nonce,
46 base::StringPiece associated_data,
47 base::StringPiece plaintext,
48 unsigned char* output) override;
49 bool EncryptPacket(QuicPacketSequenceNumber sequence_number,
50 base::StringPiece associated_data,
51 base::StringPiece plaintext,
52 char* output,
53 size_t* output_length,
54 size_t max_output_length) override;
55 size_t GetKeySize() const override;
56 size_t GetNoncePrefixSize() const override;
57 size_t GetMaxPlaintextSize(size_t ciphertext_size) const override;
58 size_t GetCiphertextSize(size_t plaintext_size) const override;
59 base::StringPiece GetKey() const override;
60 base::StringPiece GetNoncePrefix() const override;
61
62 protected:
63 // Make these constants available to the subclasses so that the subclasses
64 // can assert at compile time their key_size_ and nonce_prefix_size_ do not
65 // exceed the maximum.
66 static const size_t kMaxKeySize = 32;
67 static const size_t kMaxNoncePrefixSize = 4;
68
69 #if !defined(USE_OPENSSL)
70 struct AeadParams {
71 unsigned int len;
72 union {
73 CK_GCM_PARAMS gcm_params;
74 #if !defined(USE_NSS)
75 // USE_NSS means we are using system NSS rather than our copy of NSS.
76 // The system NSS <pkcs11n.h> header doesn't define this type yet.
77 CK_NSS_AEAD_PARAMS nss_aead_params;
78 #endif
79 } data;
80 };
81
82 virtual void FillAeadParams(base::StringPiece nonce,
83 base::StringPiece associated_data,
84 size_t auth_tag_size,
85 AeadParams* aead_params) const = 0;
86 #endif
87
88 private:
89 #if defined(USE_OPENSSL)
90 const EVP_AEAD* const aead_alg_;
91 #else
92 const CK_MECHANISM_TYPE aead_mechanism_;
93 const PK11_EncryptFunction pk11_encrypt_;
94 #endif
95 const size_t key_size_;
96 const size_t auth_tag_size_;
97 const size_t nonce_prefix_size_;
98
99 // The key.
100 unsigned char key_[kMaxKeySize];
101 // The nonce prefix.
102 unsigned char nonce_prefix_[kMaxNoncePrefixSize];
103
104 #if defined(USE_OPENSSL)
105 ScopedEVPAEADCtx ctx_;
106 #endif
107
108 DISALLOW_COPY_AND_ASSIGN(AeadBaseEncrypter);
109 };
110
111 } // namespace net
112
113 #endif // NET_QUIC_CRYPTO_AEAD_BASE_ENCRYPTER_H_
OLDNEW
« no previous file with comments | « net/quic/crypto/aead_base_decrypter_openssl.cc ('k') | net/quic/crypto/aead_base_encrypter_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698