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

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: removed JWK AES alg key length validation, replaced with TODO Created 7 years, 1 month 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 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 WebKit::WebCryptoAlgorithm& algorithm) { 179 const WebKit::WebCryptoAlgorithm& algorithm) {
179 DCHECK_EQ(algorithm.id(), WebKit::WebCryptoAlgorithmIdHmac); 180 DCHECK_EQ(algorithm.id(), WebKit::WebCryptoAlgorithmIdHmac);
180 const WebKit::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); 181 const WebKit::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams();
181 DCHECK(params); 182 DCHECK(params);
182 switch (params->hash().id()) { 183 switch (params->hash().id()) {
183 case WebKit::WebCryptoAlgorithmIdSha1: 184 case WebKit::WebCryptoAlgorithmIdSha1:
(...skipping 27 matching lines...) Expand all
211 return 512; 212 return 512;
212 case WebKit::WebCryptoAlgorithmIdSha256: 213 case WebKit::WebCryptoAlgorithmIdSha256:
213 return 512; 214 return 512;
214 default: 215 default:
215 return 0; 216 return 0;
216 } 217 }
217 } 218 }
218 219
219 // Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros, 220 // Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros,
220 // to unsigned long. 221 // to unsigned long.
221 bool BigIntegerToLong(const uint8* data, 222 bool BigIntegerToLong(const uint8* data,
eroman 2013/11/07 20:54:37 Side-comment: this would be a good candidate to mo
222 unsigned data_size, 223 unsigned data_size,
223 unsigned long* result) { 224 unsigned long* result) {
224 // TODO(padolph): Is it correct to say that empty data is an error, or does it 225 // TODO(padolph): Is it correct to say that empty data is an error, or does it
225 // mean value 0? See https://www.w3.org/Bugs/Public/show_bug.cgi?id=23655 226 // mean value 0? See https://www.w3.org/Bugs/Public/show_bug.cgi?id=23655
226 if (data_size == 0) 227 if (data_size == 0)
227 return false; 228 return false;
228 229
229 *result = 0; 230 *result = 0;
230 for (size_t i = 0; i < data_size; ++i) { 231 for (size_t i = 0; i < data_size; ++i) {
231 size_t reverse_i = data_size - i - 1; 232 size_t reverse_i = data_size - i - 1;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 break; 643 break;
643 } 644 }
644 default: 645 default:
645 return false; 646 return false;
646 } 647 }
647 648
648 return true; 649 return true;
649 } 650 }
650 651
651 } // namespace content 652 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698