| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 #include <sechash.h> | 9 #include <sechash.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "content/renderer/webcrypto/webcrypto_util.h" |
| 14 #include "crypto/nss_util.h" | 15 #include "crypto/nss_util.h" |
| 15 #include "crypto/scoped_nss_types.h" | 16 #include "crypto/scoped_nss_types.h" |
| 16 #include "crypto/secure_util.h" | 17 #include "crypto/secure_util.h" |
| 17 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 18 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| 18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 141 } |
| 141 | 142 |
| 142 unsigned int final_output_chunk_len; | 143 unsigned int final_output_chunk_len; |
| 143 if (SECSuccess != PK11_DigestFinal(context.get(), | 144 if (SECSuccess != PK11_DigestFinal(context.get(), |
| 144 buffer_data + output_len, | 145 buffer_data + output_len, |
| 145 &final_output_chunk_len, | 146 &final_output_chunk_len, |
| 146 output_max_len - output_len)) { | 147 output_max_len - output_len)) { |
| 147 return false; | 148 return false; |
| 148 } | 149 } |
| 149 | 150 |
| 150 WebCryptoImpl::ShrinkBuffer(buffer, final_output_chunk_len + output_len); | 151 ShrinkBuffer(buffer, final_output_chunk_len + output_len); |
| 151 return true; | 152 return true; |
| 152 } | 153 } |
| 153 | 154 |
| 154 CK_MECHANISM_TYPE HmacAlgorithmToGenMechanism( | 155 CK_MECHANISM_TYPE HmacAlgorithmToGenMechanism( |
| 155 const WebKit::WebCryptoAlgorithm& algorithm) { | 156 const WebKit::WebCryptoAlgorithm& algorithm) { |
| 156 DCHECK_EQ(algorithm.id(), WebKit::WebCryptoAlgorithmIdHmac); | 157 DCHECK_EQ(algorithm.id(), WebKit::WebCryptoAlgorithmIdHmac); |
| 157 const WebKit::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); | 158 const WebKit::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); |
| 158 DCHECK(params); | 159 DCHECK(params); |
| 159 switch (params->hash().id()) { | 160 switch (params->hash().id()) { |
| 160 case WebKit::WebCryptoAlgorithmIdSha1: | 161 case WebKit::WebCryptoAlgorithmIdSha1: |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 break; | 500 break; |
| 500 } | 501 } |
| 501 default: | 502 default: |
| 502 return false; | 503 return false; |
| 503 } | 504 } |
| 504 | 505 |
| 505 return true; | 506 return true; |
| 506 } | 507 } |
| 507 | 508 |
| 508 } // namespace content | 509 } // namespace content |
| OLD | NEW |