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/webcrypto_util.h" | 5 #include "content/child/webcrypto/webcrypto_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); | 112 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); |
113 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 113 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
114 blink::WebCryptoAlgorithmIdHmac, | 114 blink::WebCryptoAlgorithmIdHmac, |
115 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); | 115 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); |
116 } | 116 } |
117 | 117 |
118 blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( | 118 blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( |
119 blink::WebCryptoAlgorithmId id, | 119 blink::WebCryptoAlgorithmId id, |
120 blink::WebCryptoAlgorithmId hash_id) { | 120 blink::WebCryptoAlgorithmId hash_id) { |
121 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); | 121 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); |
122 DCHECK(id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | |
123 id == blink::WebCryptoAlgorithmIdRsaOaep); | |
124 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 122 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
125 id, new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | 123 id, new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); |
126 } | 124 } |
127 | 125 |
128 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, | 126 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, |
129 blink::WebCryptoKeyUsageMask b) { | 127 blink::WebCryptoKeyUsageMask b) { |
130 return (a & b) == b; | 128 return (a & b) == b; |
131 } | 129 } |
132 | 130 |
133 // TODO(eroman): Move this helper to WebCryptoKey. | 131 // TODO(eroman): Move this helper to WebCryptoKey. |
134 bool KeyUsageAllows(const blink::WebCryptoKey& key, | 132 bool KeyUsageAllows(const blink::WebCryptoKey& key, |
135 const blink::WebCryptoKeyUsage usage) { | 133 const blink::WebCryptoKeyUsage usage) { |
136 return ((key.usages() & usage) != 0); | 134 return ((key.usages() & usage) != 0); |
137 } | 135 } |
138 | 136 |
139 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { | 137 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { |
140 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || | 138 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || |
141 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; | 139 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
| 140 alg_id == blink::WebCryptoAlgorithmIdRsaPss; |
142 } | 141 } |
143 | 142 |
144 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) { | 143 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) { |
145 // TODO(padolph): include all other asymmetric algorithms once they are | 144 // TODO(padolph): include all other asymmetric algorithms once they are |
146 // defined, e.g. EC and DH. | 145 // defined, e.g. EC and DH. |
147 return IsAlgorithmRsa(alg_id); | 146 return IsAlgorithmRsa(alg_id); |
148 } | 147 } |
149 | 148 |
150 // The WebCrypto spec defines the default value for the tag length, as well as | 149 // The WebCrypto spec defines the default value for the tag length, as well as |
151 // the allowed values for tag length. | 150 // the allowed values for tag length. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // avoid feeding OpenSSL data that will hang use a whitelist. | 248 // avoid feeding OpenSSL data that will hang use a whitelist. |
250 if (*public_exponent != 3 && *public_exponent != 65537) | 249 if (*public_exponent != 3 && *public_exponent != 65537) |
251 return Status::ErrorGenerateKeyPublicExponent(); | 250 return Status::ErrorGenerateKeyPublicExponent(); |
252 | 251 |
253 return Status::Success(); | 252 return Status::Success(); |
254 } | 253 } |
255 | 254 |
256 } // namespace webcrypto | 255 } // namespace webcrypto |
257 | 256 |
258 } // namespace content | 257 } // namespace content |
OLD | NEW |