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" |
| 11 #include "base/stl_util.h" |
11 #include "content/child/webcrypto/algorithm_implementation.h" | 12 #include "content/child/webcrypto/algorithm_implementation.h" |
12 #include "content/child/webcrypto/crypto_data.h" | 13 #include "content/child/webcrypto/crypto_data.h" |
13 #include "content/child/webcrypto/jwk.h" | 14 #include "content/child/webcrypto/jwk.h" |
14 #include "content/child/webcrypto/nss/key_nss.h" | 15 #include "content/child/webcrypto/nss/key_nss.h" |
15 #include "content/child/webcrypto/nss/sym_key_nss.h" | 16 #include "content/child/webcrypto/nss/sym_key_nss.h" |
16 #include "content/child/webcrypto/nss/util_nss.h" | 17 #include "content/child/webcrypto/nss/util_nss.h" |
17 #include "content/child/webcrypto/status.h" | 18 #include "content/child/webcrypto/status.h" |
18 #include "content/child/webcrypto/webcrypto_util.h" | 19 #include "content/child/webcrypto/webcrypto_util.h" |
19 #include "crypto/secure_util.h" | 20 #include "crypto/secure_util.h" |
20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 21 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 185 |
185 if (PK11_SignWithSymKey( | 186 if (PK11_SignWithSymKey( |
186 sym_key, mechanism, ¶m_item, &signature_item, &data_item) != | 187 sym_key, mechanism, ¶m_item, &signature_item, &data_item) != |
187 SECSuccess) { | 188 SECSuccess) { |
188 return Status::OperationError(); | 189 return Status::OperationError(); |
189 } | 190 } |
190 | 191 |
191 DCHECK_NE(0u, signature_item.len); | 192 DCHECK_NE(0u, signature_item.len); |
192 | 193 |
193 buffer->resize(signature_item.len); | 194 buffer->resize(signature_item.len); |
194 signature_item.data = Uint8VectorStart(buffer); | 195 signature_item.data = vector_as_array(buffer); |
195 | 196 |
196 if (PK11_SignWithSymKey( | 197 if (PK11_SignWithSymKey( |
197 sym_key, mechanism, ¶m_item, &signature_item, &data_item) != | 198 sym_key, mechanism, ¶m_item, &signature_item, &data_item) != |
198 SECSuccess) { | 199 SECSuccess) { |
199 return Status::OperationError(); | 200 return Status::OperationError(); |
200 } | 201 } |
201 | 202 |
202 CHECK_EQ(buffer->size(), signature_item.len); | 203 CHECK_EQ(buffer->size(), signature_item.len); |
203 return Status::Success(); | 204 return Status::Success(); |
204 } | 205 } |
205 | 206 |
206 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, | 207 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, |
207 const blink::WebCryptoKey& key, | 208 const blink::WebCryptoKey& key, |
208 const CryptoData& signature, | 209 const CryptoData& signature, |
209 const CryptoData& data, | 210 const CryptoData& data, |
210 bool* signature_match) const OVERRIDE { | 211 bool* signature_match) const OVERRIDE { |
211 std::vector<uint8_t> result; | 212 std::vector<uint8_t> result; |
212 Status status = Sign(algorithm, key, data, &result); | 213 Status status = Sign(algorithm, key, data, &result); |
213 | 214 |
214 if (status.IsError()) | 215 if (status.IsError()) |
215 return status; | 216 return status; |
216 | 217 |
217 // Do not allow verification of truncated MACs. | 218 // Do not allow verification of truncated MACs. |
218 *signature_match = result.size() == signature.byte_length() && | 219 *signature_match = result.size() == signature.byte_length() && |
219 crypto::SecureMemEqual(Uint8VectorStart(result), | 220 crypto::SecureMemEqual(vector_as_array(&result), |
220 signature.bytes(), | 221 signature.bytes(), |
221 signature.byte_length()); | 222 signature.byte_length()); |
222 | 223 |
223 return Status::Success(); | 224 return Status::Success(); |
224 } | 225 } |
225 }; | 226 }; |
226 | 227 |
227 } // namespace | 228 } // namespace |
228 | 229 |
229 AlgorithmImplementation* CreatePlatformHmacImplementation() { | 230 AlgorithmImplementation* CreatePlatformHmacImplementation() { |
230 return new HmacImplementation; | 231 return new HmacImplementation; |
231 } | 232 } |
232 | 233 |
233 } // namespace webcrypto | 234 } // namespace webcrypto |
234 | 235 |
235 } // namespace content | 236 } // namespace content |
OLD | NEW |