Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: content/renderer/webcrypto/webcrypto_impl_nss.cc

Issue 25906002: [webcrypto] Add JWK import for HMAC and AES-CBC key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missed a change from last upload Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 164 }
164 165
165 unsigned int final_output_chunk_len; 166 unsigned int final_output_chunk_len;
166 if (SECSuccess != PK11_DigestFinal(context.get(), 167 if (SECSuccess != PK11_DigestFinal(context.get(),
167 buffer_data + output_len, 168 buffer_data + output_len,
168 &final_output_chunk_len, 169 &final_output_chunk_len,
169 output_max_len - output_len)) { 170 output_max_len - output_len)) {
170 return false; 171 return false;
171 } 172 }
172 173
173 WebCryptoImpl::ShrinkBuffer(buffer, final_output_chunk_len + output_len); 174 webcrypto::ShrinkBuffer(buffer, final_output_chunk_len + output_len);
174 return true; 175 return true;
175 } 176 }
176 177
177 CK_MECHANISM_TYPE HmacAlgorithmToGenMechanism( 178 CK_MECHANISM_TYPE HmacAlgorithmToGenMechanism(
178 const blink::WebCryptoAlgorithm& algorithm) { 179 const blink::WebCryptoAlgorithm& algorithm) {
179 DCHECK_EQ(algorithm.id(), blink::WebCryptoAlgorithmIdHmac); 180 DCHECK_EQ(algorithm.id(), blink::WebCryptoAlgorithmIdHmac);
180 const blink::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); 181 const blink::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams();
181 DCHECK(params); 182 DCHECK(params);
182 switch (params->hash().id()) { 183 switch (params->hash().id()) {
183 case blink::WebCryptoAlgorithmIdSha1: 184 case blink::WebCryptoAlgorithmIdSha1:
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 unsigned output_length_bytes = 0; 578 unsigned output_length_bytes = 0;
578 if (PK11_PrivDecryptPKCS1(private_key->key(), 579 if (PK11_PrivDecryptPKCS1(private_key->key(),
579 buffer_data, 580 buffer_data,
580 &output_length_bytes, 581 &output_length_bytes,
581 max_output_length_bytes, 582 max_output_length_bytes,
582 const_cast<unsigned char*>(data), 583 const_cast<unsigned char*>(data),
583 data_size) != SECSuccess) { 584 data_size) != SECSuccess) {
584 return false; 585 return false;
585 } 586 }
586 DCHECK_LE(output_length_bytes, max_output_length_bytes); 587 DCHECK_LE(output_length_bytes, max_output_length_bytes);
587 WebCryptoImpl::ShrinkBuffer(buffer, output_length_bytes); 588 webcrypto::ShrinkBuffer(buffer, output_length_bytes);
588 return true; 589 return true;
589 } 590 }
590 591
591 return false; 592 return false;
592 } 593 }
593 594
594 bool WebCryptoImpl::DigestInternal( 595 bool WebCryptoImpl::DigestInternal(
595 const blink::WebCryptoAlgorithm& algorithm, 596 const blink::WebCryptoAlgorithm& algorithm,
596 const unsigned char* data, 597 const unsigned char* data,
597 unsigned data_size, 598 unsigned data_size,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 break; 930 break;
930 } 931 }
931 default: 932 default:
932 return false; 933 return false;
933 } 934 }
934 935
935 return true; 936 return true;
936 } 937 }
937 938
938 } // namespace content 939 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl.cc ('k') | content/renderer/webcrypto/webcrypto_impl_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698