| OLD | NEW |
| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 aes_gcm_(CreatePlatformAesGcmImplementation()), | 23 aes_gcm_(CreatePlatformAesGcmImplementation()), |
| 24 aes_cbc_(CreatePlatformAesCbcImplementation()), | 24 aes_cbc_(CreatePlatformAesCbcImplementation()), |
| 25 aes_ctr_(CreatePlatformAesCtrImplementation()), | 25 aes_ctr_(CreatePlatformAesCtrImplementation()), |
| 26 aes_kw_(CreatePlatformAesKwImplementation()), | 26 aes_kw_(CreatePlatformAesKwImplementation()), |
| 27 hmac_(CreatePlatformHmacImplementation()), | 27 hmac_(CreatePlatformHmacImplementation()), |
| 28 rsa_ssa_(CreatePlatformRsaSsaImplementation()), | 28 rsa_ssa_(CreatePlatformRsaSsaImplementation()), |
| 29 rsa_oaep_(CreatePlatformRsaOaepImplementation()), | 29 rsa_oaep_(CreatePlatformRsaOaepImplementation()), |
| 30 rsa_pss_(CreatePlatformRsaPssImplementation()), | 30 rsa_pss_(CreatePlatformRsaPssImplementation()), |
| 31 ecdsa_(CreatePlatformEcdsaImplementation()), | 31 ecdsa_(CreatePlatformEcdsaImplementation()), |
| 32 ecdh_(CreatePlatformEcdhImplementation()), | 32 ecdh_(CreatePlatformEcdhImplementation()), |
| 33 hkdf_(CreatePlatformHkdfImplementation()) { | 33 hkdf_(CreatePlatformHkdfImplementation()), |
| 34 pbkdf2_(CreatePlatformPbkdf2Implementation()) { |
| 34 PlatformInit(); | 35 PlatformInit(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 const AlgorithmImplementation* GetAlgorithm( | 38 const AlgorithmImplementation* GetAlgorithm( |
| 38 blink::WebCryptoAlgorithmId id) const { | 39 blink::WebCryptoAlgorithmId id) const { |
| 39 switch (id) { | 40 switch (id) { |
| 40 case blink::WebCryptoAlgorithmIdSha1: | 41 case blink::WebCryptoAlgorithmIdSha1: |
| 41 case blink::WebCryptoAlgorithmIdSha256: | 42 case blink::WebCryptoAlgorithmIdSha256: |
| 42 case blink::WebCryptoAlgorithmIdSha384: | 43 case blink::WebCryptoAlgorithmIdSha384: |
| 43 case blink::WebCryptoAlgorithmIdSha512: | 44 case blink::WebCryptoAlgorithmIdSha512: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 case blink::WebCryptoAlgorithmIdRsaOaep: | 58 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 58 return rsa_oaep_.get(); | 59 return rsa_oaep_.get(); |
| 59 case blink::WebCryptoAlgorithmIdRsaPss: | 60 case blink::WebCryptoAlgorithmIdRsaPss: |
| 60 return rsa_pss_.get(); | 61 return rsa_pss_.get(); |
| 61 case blink::WebCryptoAlgorithmIdEcdsa: | 62 case blink::WebCryptoAlgorithmIdEcdsa: |
| 62 return ecdsa_.get(); | 63 return ecdsa_.get(); |
| 63 case blink::WebCryptoAlgorithmIdEcdh: | 64 case blink::WebCryptoAlgorithmIdEcdh: |
| 64 return ecdh_.get(); | 65 return ecdh_.get(); |
| 65 case blink::WebCryptoAlgorithmIdHkdf: | 66 case blink::WebCryptoAlgorithmIdHkdf: |
| 66 return hkdf_.get(); | 67 return hkdf_.get(); |
| 68 case blink::WebCryptoAlgorithmIdPbkdf2: |
| 69 return pbkdf2_.get(); |
| 67 default: | 70 default: |
| 68 return NULL; | 71 return NULL; |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| 72 private: | 75 private: |
| 73 const scoped_ptr<AlgorithmImplementation> sha_; | 76 const scoped_ptr<AlgorithmImplementation> sha_; |
| 74 const scoped_ptr<AlgorithmImplementation> aes_gcm_; | 77 const scoped_ptr<AlgorithmImplementation> aes_gcm_; |
| 75 const scoped_ptr<AlgorithmImplementation> aes_cbc_; | 78 const scoped_ptr<AlgorithmImplementation> aes_cbc_; |
| 76 const scoped_ptr<AlgorithmImplementation> aes_ctr_; | 79 const scoped_ptr<AlgorithmImplementation> aes_ctr_; |
| 77 const scoped_ptr<AlgorithmImplementation> aes_kw_; | 80 const scoped_ptr<AlgorithmImplementation> aes_kw_; |
| 78 const scoped_ptr<AlgorithmImplementation> hmac_; | 81 const scoped_ptr<AlgorithmImplementation> hmac_; |
| 79 const scoped_ptr<AlgorithmImplementation> rsa_ssa_; | 82 const scoped_ptr<AlgorithmImplementation> rsa_ssa_; |
| 80 const scoped_ptr<AlgorithmImplementation> rsa_oaep_; | 83 const scoped_ptr<AlgorithmImplementation> rsa_oaep_; |
| 81 const scoped_ptr<AlgorithmImplementation> rsa_pss_; | 84 const scoped_ptr<AlgorithmImplementation> rsa_pss_; |
| 82 const scoped_ptr<AlgorithmImplementation> ecdsa_; | 85 const scoped_ptr<AlgorithmImplementation> ecdsa_; |
| 83 const scoped_ptr<AlgorithmImplementation> ecdh_; | 86 const scoped_ptr<AlgorithmImplementation> ecdh_; |
| 84 const scoped_ptr<AlgorithmImplementation> hkdf_; | 87 const scoped_ptr<AlgorithmImplementation> hkdf_; |
| 88 const scoped_ptr<AlgorithmImplementation> pbkdf2_; |
| 85 }; | 89 }; |
| 86 | 90 |
| 87 } // namespace | 91 } // namespace |
| 88 | 92 |
| 89 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = | 93 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = |
| 90 LAZY_INSTANCE_INITIALIZER; | 94 LAZY_INSTANCE_INITIALIZER; |
| 91 | 95 |
| 92 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, | 96 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, |
| 93 const AlgorithmImplementation** impl) { | 97 const AlgorithmImplementation** impl) { |
| 94 *impl = g_algorithm_registry.Get().GetAlgorithm(id); | 98 *impl = g_algorithm_registry.Get().GetAlgorithm(id); |
| 95 if (*impl) | 99 if (*impl) |
| 96 return Status::Success(); | 100 return Status::Success(); |
| 97 return Status::ErrorUnsupported(); | 101 return Status::ErrorUnsupported(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 } // namespace webcrypto | 104 } // namespace webcrypto |
| 101 | 105 |
| 102 } // namespace content | 106 } // namespace content |
| OLD | NEW |