| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 bool KeyUsageAllows(const blink::WebCryptoKey& key, | 133 bool KeyUsageAllows(const blink::WebCryptoKey& key, |
| 134 const blink::WebCryptoKeyUsage usage) { | 134 const blink::WebCryptoKeyUsage usage) { |
| 135 return ((key.usages() & usage) != 0); | 135 return ((key.usages() & usage) != 0); |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { | 138 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { |
| 139 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || | 139 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || |
| 140 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; | 140 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; |
| 141 } | 141 } |
| 142 | 142 |
| 143 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) { | |
| 144 // TODO(padolph): include all other asymmetric algorithms once they are | |
| 145 // defined, e.g. EC and DH. | |
| 146 return IsAlgorithmRsa(alg_id); | |
| 147 } | |
| 148 | |
| 149 // The WebCrypto spec defines the default value for the tag length, as well as | 143 // The WebCrypto spec defines the default value for the tag length, as well as |
| 150 // the allowed values for tag length. | 144 // the allowed values for tag length. |
| 151 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, | 145 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, |
| 152 unsigned int* tag_length_bits) { | 146 unsigned int* tag_length_bits) { |
| 153 *tag_length_bits = 128; | 147 *tag_length_bits = 128; |
| 154 if (params->hasTagLengthBits()) | 148 if (params->hasTagLengthBits()) |
| 155 *tag_length_bits = params->optionalTagLengthBits(); | 149 *tag_length_bits = params->optionalTagLengthBits(); |
| 156 | 150 |
| 157 if (*tag_length_bits != 32 && *tag_length_bits != 64 && | 151 if (*tag_length_bits != 32 && *tag_length_bits != 64 && |
| 158 *tag_length_bits != 96 && *tag_length_bits != 104 && | 152 *tag_length_bits != 96 && *tag_length_bits != 104 && |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // avoid feeding OpenSSL data that will hang use a whitelist. | 242 // avoid feeding OpenSSL data that will hang use a whitelist. |
| 249 if (*public_exponent != 3 && *public_exponent != 65537) | 243 if (*public_exponent != 3 && *public_exponent != 65537) |
| 250 return Status::ErrorGenerateKeyPublicExponent(); | 244 return Status::ErrorGenerateKeyPublicExponent(); |
| 251 | 245 |
| 252 return Status::Success(); | 246 return Status::Success(); |
| 253 } | 247 } |
| 254 | 248 |
| 255 } // namespace webcrypto | 249 } // namespace webcrypto |
| 256 | 250 |
| 257 } // namespace content | 251 } // namespace content |
| OLD | NEW |