Chromium Code Reviews| 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 <openssl/hmac.h> | 5 #include <openssl/hmac.h> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_math.h" | 8 #include "base/numerics/safe_math.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "content/child/webcrypto/algorithm_implementation.h" | 10 #include "content/child/webcrypto/algorithm_implementation.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 } | 63 } |
| 64 | 64 |
| 65 class HmacImplementation : public AlgorithmImplementation { | 65 class HmacImplementation : public AlgorithmImplementation { |
| 66 public: | 66 public: |
| 67 HmacImplementation() {} | 67 HmacImplementation() {} |
| 68 | 68 |
| 69 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, | 69 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
| 70 bool extractable, | 70 bool extractable, |
| 71 blink::WebCryptoKeyUsageMask usages, | 71 blink::WebCryptoKeyUsageMask usages, |
| 72 GenerateKeyResult* result) const override { | 72 GenerateKeyResult* result) const override { |
| 73 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages); | 73 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages, false); |
|
eroman
2014/12/09 21:04:46
Same comment as earlier.
| |
| 74 if (status.IsError()) | 74 if (status.IsError()) |
| 75 return status; | 75 return status; |
| 76 | 76 |
| 77 const blink::WebCryptoHmacKeyGenParams* params = | 77 const blink::WebCryptoHmacKeyGenParams* params = |
| 78 algorithm.hmacKeyGenParams(); | 78 algorithm.hmacKeyGenParams(); |
| 79 | 79 |
| 80 unsigned int keylen_bits = 0; | 80 unsigned int keylen_bits = 0; |
| 81 status = GetHmacKeyGenLengthInBits(params, &keylen_bits); | 81 status = GetHmacKeyGenLengthInBits(params, &keylen_bits); |
| 82 if (status.IsError()) | 82 if (status.IsError()) |
| 83 return status; | 83 return status; |
| 84 | 84 |
| 85 return GenerateSecretKeyOpenSsl(blink::WebCryptoKeyAlgorithm::createHmac( | 85 return GenerateSecretKeyOpenSsl(blink::WebCryptoKeyAlgorithm::createHmac( |
| 86 params->hash().id(), keylen_bits), | 86 params->hash().id(), keylen_bits), |
| 87 extractable, usages, keylen_bits / 8, | 87 extractable, usages, keylen_bits / 8, |
| 88 result); | 88 result); |
| 89 } | 89 } |
| 90 | 90 |
| 91 Status VerifyKeyUsagesBeforeImportKey( | 91 Status VerifyKeyUsagesBeforeImportKey( |
| 92 blink::WebCryptoKeyFormat format, | 92 blink::WebCryptoKeyFormat format, |
| 93 blink::WebCryptoKeyUsageMask usages) const override { | 93 blink::WebCryptoKeyUsageMask usages) const override { |
| 94 switch (format) { | 94 switch (format) { |
| 95 case blink::WebCryptoKeyFormatRaw: | 95 case blink::WebCryptoKeyFormatRaw: |
| 96 case blink::WebCryptoKeyFormatJwk: | 96 case blink::WebCryptoKeyFormatJwk: |
| 97 return CheckKeyCreationUsages(kAllKeyUsages, usages); | 97 return CheckKeyCreationUsages(kAllKeyUsages, usages, true); |
| 98 default: | 98 default: |
| 99 return Status::ErrorUnsupportedImportKeyFormat(); | 99 return Status::ErrorUnsupportedImportKeyFormat(); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 Status ImportKeyRaw(const CryptoData& key_data, | 103 Status ImportKeyRaw(const CryptoData& key_data, |
| 104 const blink::WebCryptoAlgorithm& algorithm, | 104 const blink::WebCryptoAlgorithm& algorithm, |
| 105 bool extractable, | 105 bool extractable, |
| 106 blink::WebCryptoKeyUsageMask usages, | 106 blink::WebCryptoKeyUsageMask usages, |
| 107 blink::WebCryptoKey* key) const override { | 107 blink::WebCryptoKey* key) const override { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 214 |
| 215 } // namespace | 215 } // namespace |
| 216 | 216 |
| 217 AlgorithmImplementation* CreatePlatformHmacImplementation() { | 217 AlgorithmImplementation* CreatePlatformHmacImplementation() { |
| 218 return new HmacImplementation; | 218 return new HmacImplementation; |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace webcrypto | 221 } // namespace webcrypto |
| 222 | 222 |
| 223 } // namespace content | 223 } // namespace content |
| OLD | NEW |