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

Side by Side Diff: content/child/webcrypto/algorithm_registry.cc

Issue 491763002: [webcrypto] Implement AES-CTR using BoringSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase onto master (moves unittest to its own file) Created 6 years, 3 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
« no previous file with comments | « no previous file | content/child/webcrypto/nss/util_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/child/webcrypto/algorithm_registry.h" 5 #include "content/child/webcrypto/algorithm_registry.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "content/child/webcrypto/algorithm_implementation.h" 8 #include "content/child/webcrypto/algorithm_implementation.h"
9 #include "content/child/webcrypto/platform_crypto.h" 9 #include "content/child/webcrypto/platform_crypto.h"
10 #include "content/child/webcrypto/status.h" 10 #include "content/child/webcrypto/status.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 namespace webcrypto { 14 namespace webcrypto {
15 15
16 namespace { 16 namespace {
17 17
18 class AlgorithmRegistry { 18 class AlgorithmRegistry {
19 public: 19 public:
20 AlgorithmRegistry() 20 AlgorithmRegistry()
21 : sha_(CreatePlatformShaImplementation()), 21 : sha_(CreatePlatformShaImplementation()),
22 aes_gcm_(CreatePlatformAesGcmImplementation()), 22 aes_gcm_(CreatePlatformAesGcmImplementation()),
23 aes_cbc_(CreatePlatformAesCbcImplementation()), 23 aes_cbc_(CreatePlatformAesCbcImplementation()),
24 aes_ctr_(CreatePlatformAesCtrImplementation()),
24 aes_kw_(CreatePlatformAesKwImplementation()), 25 aes_kw_(CreatePlatformAesKwImplementation()),
25 hmac_(CreatePlatformHmacImplementation()), 26 hmac_(CreatePlatformHmacImplementation()),
26 rsa_ssa_(CreatePlatformRsaSsaImplementation()), 27 rsa_ssa_(CreatePlatformRsaSsaImplementation()),
27 rsa_oaep_(CreatePlatformRsaOaepImplementation()) { 28 rsa_oaep_(CreatePlatformRsaOaepImplementation()) {
28 PlatformInit(); 29 PlatformInit();
29 } 30 }
30 31
31 const AlgorithmImplementation* GetAlgorithm( 32 const AlgorithmImplementation* GetAlgorithm(
32 blink::WebCryptoAlgorithmId id) const { 33 blink::WebCryptoAlgorithmId id) const {
33 switch (id) { 34 switch (id) {
34 case blink::WebCryptoAlgorithmIdSha1: 35 case blink::WebCryptoAlgorithmIdSha1:
35 case blink::WebCryptoAlgorithmIdSha256: 36 case blink::WebCryptoAlgorithmIdSha256:
36 case blink::WebCryptoAlgorithmIdSha384: 37 case blink::WebCryptoAlgorithmIdSha384:
37 case blink::WebCryptoAlgorithmIdSha512: 38 case blink::WebCryptoAlgorithmIdSha512:
38 return sha_.get(); 39 return sha_.get();
39 case blink::WebCryptoAlgorithmIdAesGcm: 40 case blink::WebCryptoAlgorithmIdAesGcm:
40 return aes_gcm_.get(); 41 return aes_gcm_.get();
41 case blink::WebCryptoAlgorithmIdAesCbc: 42 case blink::WebCryptoAlgorithmIdAesCbc:
42 return aes_cbc_.get(); 43 return aes_cbc_.get();
44 case blink::WebCryptoAlgorithmIdAesCtr:
45 return aes_ctr_.get();
43 case blink::WebCryptoAlgorithmIdAesKw: 46 case blink::WebCryptoAlgorithmIdAesKw:
44 return aes_kw_.get(); 47 return aes_kw_.get();
45 case blink::WebCryptoAlgorithmIdHmac: 48 case blink::WebCryptoAlgorithmIdHmac:
46 return hmac_.get(); 49 return hmac_.get();
47 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: 50 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
48 return rsa_ssa_.get(); 51 return rsa_ssa_.get();
49 case blink::WebCryptoAlgorithmIdRsaOaep: 52 case blink::WebCryptoAlgorithmIdRsaOaep:
50 return rsa_oaep_.get(); 53 return rsa_oaep_.get();
51 default: 54 default:
52 return NULL; 55 return NULL;
53 } 56 }
54 } 57 }
55 58
56 private: 59 private:
57 scoped_ptr<AlgorithmImplementation> sha_; 60 scoped_ptr<AlgorithmImplementation> sha_;
58 scoped_ptr<AlgorithmImplementation> aes_gcm_; 61 scoped_ptr<AlgorithmImplementation> aes_gcm_;
59 scoped_ptr<AlgorithmImplementation> aes_cbc_; 62 scoped_ptr<AlgorithmImplementation> aes_cbc_;
63 scoped_ptr<AlgorithmImplementation> aes_ctr_;
60 scoped_ptr<AlgorithmImplementation> aes_kw_; 64 scoped_ptr<AlgorithmImplementation> aes_kw_;
61 scoped_ptr<AlgorithmImplementation> hmac_; 65 scoped_ptr<AlgorithmImplementation> hmac_;
62 scoped_ptr<AlgorithmImplementation> rsa_ssa_; 66 scoped_ptr<AlgorithmImplementation> rsa_ssa_;
63 scoped_ptr<AlgorithmImplementation> rsa_oaep_; 67 scoped_ptr<AlgorithmImplementation> rsa_oaep_;
64 }; 68 };
65 69
66 } // namespace 70 } // namespace
67 71
68 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = 72 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry =
69 LAZY_INSTANCE_INITIALIZER; 73 LAZY_INSTANCE_INITIALIZER;
70 74
71 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, 75 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id,
72 const AlgorithmImplementation** impl) { 76 const AlgorithmImplementation** impl) {
73 *impl = g_algorithm_registry.Get().GetAlgorithm(id); 77 *impl = g_algorithm_registry.Get().GetAlgorithm(id);
74 if (*impl) 78 if (*impl)
75 return Status::Success(); 79 return Status::Success();
76 return Status::ErrorUnsupported(); 80 return Status::ErrorUnsupported();
77 } 81 }
78 82
79 } // namespace webcrypto 83 } // namespace webcrypto
80 84
81 } // namespace content 85 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/nss/util_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698