| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 blink::WebCryptoKeyUsageMask b) { | 126 blink::WebCryptoKeyUsageMask b) { |
| 127 return (a & b) == b; | 127 return (a & b) == b; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // TODO(eroman): Move this helper to WebCryptoKey. | 130 // TODO(eroman): Move this helper to WebCryptoKey. |
| 131 bool KeyUsageAllows(const blink::WebCryptoKey& key, | 131 bool KeyUsageAllows(const blink::WebCryptoKey& key, |
| 132 const blink::WebCryptoKeyUsage usage) { | 132 const blink::WebCryptoKeyUsage usage) { |
| 133 return ((key.usages() & usage) != 0); | 133 return ((key.usages() & usage) != 0); |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { | |
| 137 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || | |
| 138 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | |
| 139 alg_id == blink::WebCryptoAlgorithmIdRsaPss; | |
| 140 } | |
| 141 | |
| 142 // The WebCrypto spec defines the default value for the tag length, as well as | 136 // The WebCrypto spec defines the default value for the tag length, as well as |
| 143 // the allowed values for tag length. | 137 // the allowed values for tag length. |
| 144 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, | 138 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, |
| 145 unsigned int* tag_length_bits) { | 139 unsigned int* tag_length_bits) { |
| 146 *tag_length_bits = 128; | 140 *tag_length_bits = 128; |
| 147 if (params->hasTagLengthBits()) | 141 if (params->hasTagLengthBits()) |
| 148 *tag_length_bits = params->optionalTagLengthBits(); | 142 *tag_length_bits = params->optionalTagLengthBits(); |
| 149 | 143 |
| 150 if (*tag_length_bits != 32 && *tag_length_bits != 64 && | 144 if (*tag_length_bits != 32 && *tag_length_bits != 64 && |
| 151 *tag_length_bits != 96 && *tag_length_bits != 104 && | 145 *tag_length_bits != 96 && *tag_length_bits != 104 && |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // avoid feeding OpenSSL data that will hang use a whitelist. | 235 // avoid feeding OpenSSL data that will hang use a whitelist. |
| 242 if (*public_exponent != 3 && *public_exponent != 65537) | 236 if (*public_exponent != 3 && *public_exponent != 65537) |
| 243 return Status::ErrorGenerateKeyPublicExponent(); | 237 return Status::ErrorGenerateKeyPublicExponent(); |
| 244 | 238 |
| 245 return Status::Success(); | 239 return Status::Success(); |
| 246 } | 240 } |
| 247 | 241 |
| 248 } // namespace webcrypto | 242 } // namespace webcrypto |
| 249 | 243 |
| 250 } // namespace content | 244 } // namespace content |
| OLD | NEW |