| 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 11 matching lines...) Expand all Loading... |
| 22 : sha_(CreatePlatformShaImplementation()), | 22 : sha_(CreatePlatformShaImplementation()), |
| 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 PlatformInit(); | 34 PlatformInit(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 const AlgorithmImplementation* GetAlgorithm( | 37 const AlgorithmImplementation* GetAlgorithm( |
| 37 blink::WebCryptoAlgorithmId id) const { | 38 blink::WebCryptoAlgorithmId id) const { |
| 38 switch (id) { | 39 switch (id) { |
| 39 case blink::WebCryptoAlgorithmIdSha1: | 40 case blink::WebCryptoAlgorithmIdSha1: |
| 40 case blink::WebCryptoAlgorithmIdSha256: | 41 case blink::WebCryptoAlgorithmIdSha256: |
| 41 case blink::WebCryptoAlgorithmIdSha384: | 42 case blink::WebCryptoAlgorithmIdSha384: |
| 42 case blink::WebCryptoAlgorithmIdSha512: | 43 case blink::WebCryptoAlgorithmIdSha512: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: | 55 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 55 return rsa_ssa_.get(); | 56 return rsa_ssa_.get(); |
| 56 case blink::WebCryptoAlgorithmIdRsaOaep: | 57 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 57 return rsa_oaep_.get(); | 58 return rsa_oaep_.get(); |
| 58 case blink::WebCryptoAlgorithmIdRsaPss: | 59 case blink::WebCryptoAlgorithmIdRsaPss: |
| 59 return rsa_pss_.get(); | 60 return rsa_pss_.get(); |
| 60 case blink::WebCryptoAlgorithmIdEcdsa: | 61 case blink::WebCryptoAlgorithmIdEcdsa: |
| 61 return ecdsa_.get(); | 62 return ecdsa_.get(); |
| 62 case blink::WebCryptoAlgorithmIdEcdh: | 63 case blink::WebCryptoAlgorithmIdEcdh: |
| 63 return ecdh_.get(); | 64 return ecdh_.get(); |
| 65 case blink::WebCryptoAlgorithmIdHkdf: |
| 66 return hkdf_.get(); |
| 64 default: | 67 default: |
| 65 return NULL; | 68 return NULL; |
| 66 } | 69 } |
| 67 } | 70 } |
| 68 | 71 |
| 69 private: | 72 private: |
| 70 const scoped_ptr<AlgorithmImplementation> sha_; | 73 const scoped_ptr<AlgorithmImplementation> sha_; |
| 71 const scoped_ptr<AlgorithmImplementation> aes_gcm_; | 74 const scoped_ptr<AlgorithmImplementation> aes_gcm_; |
| 72 const scoped_ptr<AlgorithmImplementation> aes_cbc_; | 75 const scoped_ptr<AlgorithmImplementation> aes_cbc_; |
| 73 const scoped_ptr<AlgorithmImplementation> aes_ctr_; | 76 const scoped_ptr<AlgorithmImplementation> aes_ctr_; |
| 74 const scoped_ptr<AlgorithmImplementation> aes_kw_; | 77 const scoped_ptr<AlgorithmImplementation> aes_kw_; |
| 75 const scoped_ptr<AlgorithmImplementation> hmac_; | 78 const scoped_ptr<AlgorithmImplementation> hmac_; |
| 76 const scoped_ptr<AlgorithmImplementation> rsa_ssa_; | 79 const scoped_ptr<AlgorithmImplementation> rsa_ssa_; |
| 77 const scoped_ptr<AlgorithmImplementation> rsa_oaep_; | 80 const scoped_ptr<AlgorithmImplementation> rsa_oaep_; |
| 78 const scoped_ptr<AlgorithmImplementation> rsa_pss_; | 81 const scoped_ptr<AlgorithmImplementation> rsa_pss_; |
| 79 const scoped_ptr<AlgorithmImplementation> ecdsa_; | 82 const scoped_ptr<AlgorithmImplementation> ecdsa_; |
| 80 const scoped_ptr<AlgorithmImplementation> ecdh_; | 83 const scoped_ptr<AlgorithmImplementation> ecdh_; |
| 84 const scoped_ptr<AlgorithmImplementation> hkdf_; |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 } // namespace | 87 } // namespace |
| 84 | 88 |
| 85 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = | 89 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = |
| 86 LAZY_INSTANCE_INITIALIZER; | 90 LAZY_INSTANCE_INITIALIZER; |
| 87 | 91 |
| 88 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, | 92 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, |
| 89 const AlgorithmImplementation** impl) { | 93 const AlgorithmImplementation** impl) { |
| 90 *impl = g_algorithm_registry.Get().GetAlgorithm(id); | 94 *impl = g_algorithm_registry.Get().GetAlgorithm(id); |
| 91 if (*impl) | 95 if (*impl) |
| 92 return Status::Success(); | 96 return Status::Success(); |
| 93 return Status::ErrorUnsupported(); | 97 return Status::ErrorUnsupported(); |
| 94 } | 98 } |
| 95 | 99 |
| 96 } // namespace webcrypto | 100 } // namespace webcrypto |
| 97 | 101 |
| 98 } // namespace content | 102 } // namespace content |
| OLD | NEW |