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

Side by Side Diff: Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp

Issue 789733009: Implement HKDF for WebCrypto (blink-side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: move ASSERT(), add break Created 5 years, 11 months 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 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 "config.h" 5 #include "config.h"
6 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" 6 #include "bindings/modules/v8/ScriptValueSerializerForModules.h"
7 7
8 #include "bindings/core/v8/SerializationTag.h" 8 #include "bindings/core/v8/SerializationTag.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/modules/v8/V8CryptoKey.h" 10 #include "bindings/modules/v8/V8CryptoKey.h"
(...skipping 12 matching lines...) Expand all
23 Sha256Tag = 6, 23 Sha256Tag = 6,
24 Sha384Tag = 7, 24 Sha384Tag = 7,
25 Sha512Tag = 8, 25 Sha512Tag = 8,
26 AesGcmTag = 9, 26 AesGcmTag = 9,
27 RsaOaepTag = 10, 27 RsaOaepTag = 10,
28 AesCtrTag = 11, 28 AesCtrTag = 11,
29 AesKwTag = 12, 29 AesKwTag = 12,
30 RsaPssTag = 13, 30 RsaPssTag = 13,
31 EcdsaTag = 14, 31 EcdsaTag = 14,
32 EcdhTag = 15, 32 EcdhTag = 15,
33 HkdfTag = 16,
33 // Maximum allowed value is 2^32-1 34 // Maximum allowed value is 2^32-1
34 }; 35 };
35 36
36 enum NamedCurveTag { 37 enum NamedCurveTag {
37 P256Tag = 1, 38 P256Tag = 1,
38 P384Tag = 2, 39 P384Tag = 2,
39 P521Tag = 3, 40 P521Tag = 3,
40 }; 41 };
41 42
42 enum CryptoKeyUsage { 43 enum CryptoKeyUsage {
(...skipping 11 matching lines...) Expand all
54 DeriveBitsUsage = 1 << 8, 55 DeriveBitsUsage = 1 << 8,
55 // Maximum allowed value is 1 << 31 56 // Maximum allowed value is 1 << 31
56 }; 57 };
57 58
58 enum CryptoKeySubTag { 59 enum CryptoKeySubTag {
59 AesKeyTag = 1, 60 AesKeyTag = 1,
60 HmacKeyTag = 2, 61 HmacKeyTag = 2,
61 // ID 3 was used by RsaKeyTag, while still behind experimental flag. 62 // ID 3 was used by RsaKeyTag, while still behind experimental flag.
62 RsaHashedKeyTag = 4, 63 RsaHashedKeyTag = 4,
63 EcKeyTag = 5, 64 EcKeyTag = 5,
65 NoParamsKeyTag = 6,
64 // Maximum allowed value is 255 66 // Maximum allowed value is 255
65 }; 67 };
66 68
67 enum AssymetricCryptoKeyType { 69 enum AssymetricCryptoKeyType {
68 PublicKeyType = 1, 70 PublicKeyType = 1,
69 PrivateKeyType = 2, 71 PrivateKeyType = 2,
70 // Maximum allowed value is 2^32-1 72 // Maximum allowed value is 2^32-1
71 }; 73 };
72 74
73 75
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 case WebCryptoKeyAlgorithmParamsTypeHmac: 117 case WebCryptoKeyAlgorithmParamsTypeHmac:
116 doWriteHmacKey(key); 118 doWriteHmacKey(key);
117 break; 119 break;
118 case WebCryptoKeyAlgorithmParamsTypeRsaHashed: 120 case WebCryptoKeyAlgorithmParamsTypeRsaHashed:
119 doWriteRsaHashedKey(key); 121 doWriteRsaHashedKey(key);
120 break; 122 break;
121 case WebCryptoKeyAlgorithmParamsTypeEc: 123 case WebCryptoKeyAlgorithmParamsTypeEc:
122 doWriteEcKey(key); 124 doWriteEcKey(key);
123 break; 125 break;
124 case WebCryptoKeyAlgorithmParamsTypeNone: 126 case WebCryptoKeyAlgorithmParamsTypeNone:
125 ASSERT_NOT_REACHED(); 127 doWriteKeyWithoutParams(key);
126 return false; 128 break;
127 } 129 }
128 130
129 doWriteKeyUsages(key.usages(), key.extractable()); 131 doWriteKeyUsages(key.usages(), key.extractable());
130 132
131 WebVector<uint8_t> keyData; 133 WebVector<uint8_t> keyData;
132 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData)) 134 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData))
133 return false; 135 return false;
134 136
135 doWriteUint32(keyData.size()); 137 doWriteUint32(keyData.size());
136 append(keyData.data(), keyData.size()); 138 append(keyData.data(), keyData.size());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void SerializedScriptValueWriterForModules::doWriteEcKey(const WebCryptoKey& key ) 179 void SerializedScriptValueWriterForModules::doWriteEcKey(const WebCryptoKey& key )
178 { 180 {
179 ASSERT(key.algorithm().ecParams()); 181 ASSERT(key.algorithm().ecParams());
180 append(static_cast<uint8_t>(EcKeyTag)); 182 append(static_cast<uint8_t>(EcKeyTag));
181 183
182 doWriteAlgorithmId(key.algorithm().id()); 184 doWriteAlgorithmId(key.algorithm().id());
183 doWriteAsymmetricKeyType(key.type()); 185 doWriteAsymmetricKeyType(key.type());
184 doWriteNamedCurve(key.algorithm().ecParams()->namedCurve()); 186 doWriteNamedCurve(key.algorithm().ecParams()->namedCurve());
185 } 187 }
186 188
189 void SerializedScriptValueWriterForModules::doWriteKeyWithoutParams(const WebCry ptoKey& key)
190 {
191 ASSERT(WebCryptoAlgorithm::isKdf(key.algorithm().id()));
192 append(static_cast<uint8_t>(NoParamsKeyTag));
193
194 doWriteAlgorithmId(key.algorithm().id());
195 }
196
187 void SerializedScriptValueWriterForModules::doWriteAlgorithmId(WebCryptoAlgorith mId id) 197 void SerializedScriptValueWriterForModules::doWriteAlgorithmId(WebCryptoAlgorith mId id)
188 { 198 {
189 switch (id) { 199 switch (id) {
190 case WebCryptoAlgorithmIdAesCbc: 200 case WebCryptoAlgorithmIdAesCbc:
191 return doWriteUint32(AesCbcTag); 201 return doWriteUint32(AesCbcTag);
192 case WebCryptoAlgorithmIdHmac: 202 case WebCryptoAlgorithmIdHmac:
193 return doWriteUint32(HmacTag); 203 return doWriteUint32(HmacTag);
194 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: 204 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
195 return doWriteUint32(RsaSsaPkcs1v1_5Tag); 205 return doWriteUint32(RsaSsaPkcs1v1_5Tag);
196 case WebCryptoAlgorithmIdSha1: 206 case WebCryptoAlgorithmIdSha1:
(...skipping 11 matching lines...) Expand all
208 case WebCryptoAlgorithmIdAesCtr: 218 case WebCryptoAlgorithmIdAesCtr:
209 return doWriteUint32(AesCtrTag); 219 return doWriteUint32(AesCtrTag);
210 case WebCryptoAlgorithmIdAesKw: 220 case WebCryptoAlgorithmIdAesKw:
211 return doWriteUint32(AesKwTag); 221 return doWriteUint32(AesKwTag);
212 case WebCryptoAlgorithmIdRsaPss: 222 case WebCryptoAlgorithmIdRsaPss:
213 return doWriteUint32(RsaPssTag); 223 return doWriteUint32(RsaPssTag);
214 case WebCryptoAlgorithmIdEcdsa: 224 case WebCryptoAlgorithmIdEcdsa:
215 return doWriteUint32(EcdsaTag); 225 return doWriteUint32(EcdsaTag);
216 case WebCryptoAlgorithmIdEcdh: 226 case WebCryptoAlgorithmIdEcdh:
217 return doWriteUint32(EcdhTag); 227 return doWriteUint32(EcdhTag);
228 case WebCryptoAlgorithmIdHkdf:
229 return doWriteUint32(HkdfTag);
218 } 230 }
219 ASSERT_NOT_REACHED(); 231 ASSERT_NOT_REACHED();
220 } 232 }
221 233
222 void SerializedScriptValueWriterForModules::doWriteAsymmetricKeyType(WebCryptoKe yType keyType) 234 void SerializedScriptValueWriterForModules::doWriteAsymmetricKeyType(WebCryptoKe yType keyType)
223 { 235 {
224 switch (keyType) { 236 switch (keyType) {
225 case WebCryptoKeyTypePublic: 237 case WebCryptoKeyTypePublic:
226 doWriteUint32(PublicKeyType); 238 doWriteUint32(PublicKeyType);
227 break; 239 break;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return false; 364 return false;
353 break; 365 break;
354 case RsaHashedKeyTag: 366 case RsaHashedKeyTag:
355 if (!doReadRsaHashedKey(algorithm, type)) 367 if (!doReadRsaHashedKey(algorithm, type))
356 return false; 368 return false;
357 break; 369 break;
358 case EcKeyTag: 370 case EcKeyTag:
359 if (!doReadEcKey(algorithm, type)) 371 if (!doReadEcKey(algorithm, type))
360 return false; 372 return false;
361 break; 373 break;
374 case NoParamsKeyTag:
375 if (!doReadKeyWithoutParams(algorithm, type))
376 return false;
377 break;
362 default: 378 default:
363 return false; 379 return false;
364 } 380 }
365 381
366 WebCryptoKeyUsageMask usages; 382 WebCryptoKeyUsageMask usages;
367 bool extractable; 383 bool extractable;
368 if (!doReadKeyUsages(usages, extractable)) 384 if (!doReadKeyUsages(usages, extractable))
369 return false; 385 return false;
370 386
371 uint32_t keyDataLength; 387 uint32_t keyDataLength;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 return false; 467 return false;
452 468
453 WebCryptoNamedCurve namedCurve; 469 WebCryptoNamedCurve namedCurve;
454 if (!doReadNamedCurve(namedCurve)) 470 if (!doReadNamedCurve(namedCurve))
455 return false; 471 return false;
456 472
457 algorithm = WebCryptoKeyAlgorithm::createEc(id, namedCurve); 473 algorithm = WebCryptoKeyAlgorithm::createEc(id, namedCurve);
458 return !algorithm.isNull(); 474 return !algorithm.isNull();
459 } 475 }
460 476
477 bool SerializedScriptValueReaderForModules::doReadKeyWithoutParams(WebCryptoKeyA lgorithm& algorithm, WebCryptoKeyType& type)
478 {
479 WebCryptoAlgorithmId id;
480 if (!doReadAlgorithmId(id))
481 return false;
482 algorithm = WebCryptoKeyAlgorithm::createWithoutParams(id);
483 type = WebCryptoKeyTypeSecret;
484 return !algorithm.isNull();
485 }
486
461 bool SerializedScriptValueReaderForModules::doReadAlgorithmId(WebCryptoAlgorithm Id& id) 487 bool SerializedScriptValueReaderForModules::doReadAlgorithmId(WebCryptoAlgorithm Id& id)
462 { 488 {
463 uint32_t rawId; 489 uint32_t rawId;
464 if (!doReadUint32(&rawId)) 490 if (!doReadUint32(&rawId))
465 return false; 491 return false;
466 492
467 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { 493 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) {
468 case AesCbcTag: 494 case AesCbcTag:
469 id = WebCryptoAlgorithmIdAesCbc; 495 id = WebCryptoAlgorithmIdAesCbc;
470 return true; 496 return true;
(...skipping 29 matching lines...) Expand all
500 return true; 526 return true;
501 case RsaPssTag: 527 case RsaPssTag:
502 id = WebCryptoAlgorithmIdRsaPss; 528 id = WebCryptoAlgorithmIdRsaPss;
503 return true; 529 return true;
504 case EcdsaTag: 530 case EcdsaTag:
505 id = WebCryptoAlgorithmIdEcdsa; 531 id = WebCryptoAlgorithmIdEcdsa;
506 return true; 532 return true;
507 case EcdhTag: 533 case EcdhTag:
508 id = WebCryptoAlgorithmIdEcdh; 534 id = WebCryptoAlgorithmIdEcdh;
509 return true; 535 return true;
536 case HkdfTag:
537 id = WebCryptoAlgorithmIdHkdf;
538 return true;
510 } 539 }
511 540
512 return false; 541 return false;
513 } 542 }
514 543
515 bool SerializedScriptValueReaderForModules::doReadAsymmetricKeyType(WebCryptoKey Type& type) 544 bool SerializedScriptValueReaderForModules::doReadAsymmetricKeyType(WebCryptoKey Type& type)
516 { 545 {
517 uint32_t rawType; 546 uint32_t rawType;
518 if (!doReadUint32(&rawType)) 547 if (!doReadUint32(&rawType))
519 return false; 548 return false;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents) 622 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents)
594 { 623 {
595 } 624 }
596 625
597 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) 626 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value)
598 { 627 {
599 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); 628 return toSerializedScriptValueReaderForModules(reader()).read(value, *this);
600 } 629 }
601 630
602 } // namespace blink 631 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/modules/v8/ScriptValueSerializerForModules.h ('k') | Source/modules/crypto/NormalizeAlgorithm.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698