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 <cryptohi.h> | 5 #include <cryptohi.h> |
6 #include <pk11pub.h> | 6 #include <pk11pub.h> |
7 #include <secerr.h> | 7 #include <secerr.h> |
8 #include <sechash.h> | 8 #include <sechash.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 | 52 |
53 class HmacImplementation : public AlgorithmImplementation { | 53 class HmacImplementation : public AlgorithmImplementation { |
54 public: | 54 public: |
55 HmacImplementation() {} | 55 HmacImplementation() {} |
56 | 56 |
57 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, | 57 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
58 bool extractable, | 58 bool extractable, |
59 blink::WebCryptoKeyUsageMask usages, | 59 blink::WebCryptoKeyUsageMask usages, |
60 GenerateKeyResult* result) const override { | 60 GenerateKeyResult* result) const override { |
61 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages); | 61 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages, false); |
62 if (status.IsError()) | 62 if (status.IsError()) |
63 return status; | 63 return status; |
64 | 64 |
65 const blink::WebCryptoHmacKeyGenParams* params = | 65 const blink::WebCryptoHmacKeyGenParams* params = |
66 algorithm.hmacKeyGenParams(); | 66 algorithm.hmacKeyGenParams(); |
67 | 67 |
68 const blink::WebCryptoAlgorithm& hash = params->hash(); | 68 const blink::WebCryptoAlgorithm& hash = params->hash(); |
69 CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM; | 69 CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM; |
70 if (!WebCryptoHashToHMACMechanism(hash, &mechanism)) | 70 if (!WebCryptoHashToHMACMechanism(hash, &mechanism)) |
71 return Status::ErrorUnsupported(); | 71 return Status::ErrorUnsupported(); |
72 | 72 |
73 unsigned int keylen_bits = 0; | 73 unsigned int keylen_bits = 0; |
74 status = GetHmacKeyGenLengthInBits(params, &keylen_bits); | 74 status = GetHmacKeyGenLengthInBits(params, &keylen_bits); |
75 if (status.IsError()) | 75 if (status.IsError()) |
76 return status; | 76 return status; |
77 | 77 |
78 return GenerateSecretKeyNss( | 78 return GenerateSecretKeyNss( |
79 blink::WebCryptoKeyAlgorithm::createHmac(hash.id(), keylen_bits), | 79 blink::WebCryptoKeyAlgorithm::createHmac(hash.id(), keylen_bits), |
80 extractable, usages, keylen_bits, mechanism, result); | 80 extractable, usages, keylen_bits, mechanism, result); |
81 } | 81 } |
82 | 82 |
83 Status VerifyKeyUsagesBeforeImportKey( | 83 Status VerifyKeyUsagesBeforeImportKey( |
84 blink::WebCryptoKeyFormat format, | 84 blink::WebCryptoKeyFormat format, |
85 blink::WebCryptoKeyUsageMask usages) const override { | 85 blink::WebCryptoKeyUsageMask usages) const override { |
86 switch (format) { | 86 switch (format) { |
87 case blink::WebCryptoKeyFormatRaw: | 87 case blink::WebCryptoKeyFormatRaw: |
88 case blink::WebCryptoKeyFormatJwk: | 88 case blink::WebCryptoKeyFormatJwk: |
89 return CheckKeyCreationUsages(kAllKeyUsages, usages); | 89 return CheckKeyCreationUsages(kAllKeyUsages, usages, false); |
90 default: | 90 default: |
91 return Status::ErrorUnsupportedImportKeyFormat(); | 91 return Status::ErrorUnsupportedImportKeyFormat(); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 Status ImportKeyRaw(const CryptoData& key_data, | 95 Status ImportKeyRaw(const CryptoData& key_data, |
96 const blink::WebCryptoAlgorithm& algorithm, | 96 const blink::WebCryptoAlgorithm& algorithm, |
97 bool extractable, | 97 bool extractable, |
98 blink::WebCryptoKeyUsageMask usages, | 98 blink::WebCryptoKeyUsageMask usages, |
99 blink::WebCryptoKey* key) const override { | 99 blink::WebCryptoKey* key) const override { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 } // namespace | 258 } // namespace |
259 | 259 |
260 AlgorithmImplementation* CreatePlatformHmacImplementation() { | 260 AlgorithmImplementation* CreatePlatformHmacImplementation() { |
261 return new HmacImplementation; | 261 return new HmacImplementation; |
262 } | 262 } |
263 | 263 |
264 } // namespace webcrypto | 264 } // namespace webcrypto |
265 | 265 |
266 } // namespace content | 266 } // namespace content |
OLD | NEW |