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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); | 111 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); |
112 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 112 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
113 blink::WebCryptoAlgorithmIdHmac, | 113 blink::WebCryptoAlgorithmIdHmac, |
114 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); | 114 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); |
115 } | 115 } |
116 | 116 |
117 blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( | 117 blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( |
118 blink::WebCryptoAlgorithmId id, | 118 blink::WebCryptoAlgorithmId id, |
119 blink::WebCryptoAlgorithmId hash_id) { | 119 blink::WebCryptoAlgorithmId hash_id) { |
120 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); | 120 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); |
121 DCHECK(id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | |
122 id == blink::WebCryptoAlgorithmIdRsaOaep); | |
123 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 121 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
124 id, new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | 122 id, new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); |
125 } | 123 } |
126 | 124 |
127 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, | 125 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, |
128 blink::WebCryptoKeyUsageMask b) { | 126 blink::WebCryptoKeyUsageMask b) { |
129 return (a & b) == b; | 127 return (a & b) == b; |
130 } | 128 } |
131 | 129 |
132 // TODO(eroman): Move this helper to WebCryptoKey. | 130 // TODO(eroman): Move this helper to WebCryptoKey. |
133 bool KeyUsageAllows(const blink::WebCryptoKey& key, | 131 bool KeyUsageAllows(const blink::WebCryptoKey& key, |
134 const blink::WebCryptoKeyUsage usage) { | 132 const blink::WebCryptoKeyUsage usage) { |
135 return ((key.usages() & usage) != 0); | 133 return ((key.usages() & usage) != 0); |
136 } | 134 } |
137 | 135 |
138 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { | 136 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { |
139 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || | 137 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || |
140 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; | 138 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
| 139 alg_id == blink::WebCryptoAlgorithmIdRsaPss; |
141 } | 140 } |
142 | 141 |
143 // The WebCrypto spec defines the default value for the tag length, as well as | 142 // The WebCrypto spec defines the default value for the tag length, as well as |
144 // the allowed values for tag length. | 143 // the allowed values for tag length. |
145 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, | 144 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, |
146 unsigned int* tag_length_bits) { | 145 unsigned int* tag_length_bits) { |
147 *tag_length_bits = 128; | 146 *tag_length_bits = 128; |
148 if (params->hasTagLengthBits()) | 147 if (params->hasTagLengthBits()) |
149 *tag_length_bits = params->optionalTagLengthBits(); | 148 *tag_length_bits = params->optionalTagLengthBits(); |
150 | 149 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // avoid feeding OpenSSL data that will hang use a whitelist. | 241 // avoid feeding OpenSSL data that will hang use a whitelist. |
243 if (*public_exponent != 3 && *public_exponent != 65537) | 242 if (*public_exponent != 3 && *public_exponent != 65537) |
244 return Status::ErrorGenerateKeyPublicExponent(); | 243 return Status::ErrorGenerateKeyPublicExponent(); |
245 | 244 |
246 return Status::Success(); | 245 return Status::Success(); |
247 } | 246 } |
248 | 247 |
249 } // namespace webcrypto | 248 } // namespace webcrypto |
250 | 249 |
251 } // namespace content | 250 } // namespace content |
OLD | NEW |