| 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 bool KeyUsageAllows(const blink::WebCryptoKey& key, | 183 bool KeyUsageAllows(const blink::WebCryptoKey& key, |
| 184 const blink::WebCryptoKeyUsage usage) { | 184 const blink::WebCryptoKeyUsage usage) { |
| 185 return ((key.usages() & usage) != 0); | 185 return ((key.usages() & usage) != 0); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { | 188 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { |
| 189 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || | 189 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || |
| 190 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; | 190 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) { | |
| 194 // TODO(padolph): include all other asymmetric algorithms once they are | |
| 195 // defined, e.g. EC and DH. | |
| 196 return IsAlgorithmRsa(alg_id); | |
| 197 } | |
| 198 | |
| 199 // The WebCrypto spec defines the default value for the tag length, as well as | 193 // The WebCrypto spec defines the default value for the tag length, as well as |
| 200 // the allowed values for tag length. | 194 // the allowed values for tag length. |
| 201 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, | 195 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, |
| 202 unsigned int* tag_length_bits) { | 196 unsigned int* tag_length_bits) { |
| 203 *tag_length_bits = 128; | 197 *tag_length_bits = 128; |
| 204 if (params->hasTagLengthBits()) | 198 if (params->hasTagLengthBits()) |
| 205 *tag_length_bits = params->optionalTagLengthBits(); | 199 *tag_length_bits = params->optionalTagLengthBits(); |
| 206 | 200 |
| 207 if (*tag_length_bits != 32 && *tag_length_bits != 64 && | 201 if (*tag_length_bits != 32 && *tag_length_bits != 64 && |
| 208 *tag_length_bits != 96 && *tag_length_bits != 104 && | 202 *tag_length_bits != 96 && *tag_length_bits != 104 && |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // avoid feeding OpenSSL data that will hang use a whitelist. | 292 // avoid feeding OpenSSL data that will hang use a whitelist. |
| 299 if (*public_exponent != 3 && *public_exponent != 65537) | 293 if (*public_exponent != 3 && *public_exponent != 65537) |
| 300 return Status::ErrorGenerateKeyPublicExponent(); | 294 return Status::ErrorGenerateKeyPublicExponent(); |
| 301 | 295 |
| 302 return Status::Success(); | 296 return Status::Success(); |
| 303 } | 297 } |
| 304 | 298 |
| 305 } // namespace webcrypto | 299 } // namespace webcrypto |
| 306 | 300 |
| 307 } // namespace content | 301 } // namespace content |
| OLD | NEW |