Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array Buffer (ref) | 216 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array Buffer (ref) |
| 217 ArrayBufferTransferTag = 't', // index:uint32_t -> ArrayBuffer. For ArrayBuf fer transfer | 217 ArrayBufferTransferTag = 't', // index:uint32_t -> ArrayBuffer. For ArrayBuf fer transfer |
| 218 ArrayBufferViewTag = 'V', // subtag:byte, byteOffset:uint32_t, byteLength:ui nt32_t -> ArrayBufferView (ref). Consumes an ArrayBuffer from the top of the des erialization stack. | 218 ArrayBufferViewTag = 'V', // subtag:byte, byteOffset:uint32_t, byteLength:ui nt32_t -> ArrayBufferView (ref). Consumes an ArrayBuffer from the top of the des erialization stack. |
| 219 CryptoKeyTag = 'K', // subtag:byte, props, usages:uint32_t, keyDataLength:ui nt32_t, keyData:byte[keyDataLength] | 219 CryptoKeyTag = 'K', // subtag:byte, props, usages:uint32_t, keyDataLength:ui nt32_t, keyData:byte[keyDataLength] |
| 220 // If subtag=AesKeyTag: | 220 // If subtag=AesKeyTag: |
| 221 // props = keyLengthBytes:uint32_t, algorithmId:ui nt32_t | 221 // props = keyLengthBytes:uint32_t, algorithmId:ui nt32_t |
| 222 // If subtag=HmacKeyTag: | 222 // If subtag=HmacKeyTag: |
| 223 // props = keyLengthBytes:uint32_t, hashId:uint32_ t | 223 // props = keyLengthBytes:uint32_t, hashId:uint32_ t |
| 224 // If subtag=RsaHashedKeyTag: | 224 // If subtag=RsaHashedKeyTag: |
| 225 // props = algorithmId:uint32_t, type:uint32_t, mo dulusLengthBits:uint32_t, publicExponentLength:uint32_t, publicExponent:byte[pub licExponentLength], hashId:uint32_t | 225 // props = algorithmId:uint32_t, type:uint32_t, mo dulusLengthBits:uint32_t, publicExponentLength:uint32_t, publicExponent:byte[pub licExponentLength], hashId:uint32_t |
| 226 // If subtag=EcKeyTag: | |
| 227 // props = algorithmId:uint32_t, type:uint32_t, na medCurve:uint32_t | |
| 226 ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref] | 228 ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref] |
| 227 GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and pushed onto the open stack (ref) | 229 GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and pushed onto the open stack (ref) |
| 228 GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) | 230 GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) |
| 229 GenerateFreshDenseArrayTag = 'A', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) | 231 GenerateFreshDenseArrayTag = 'A', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) |
| 230 ReferenceCountTag = '?', // refTableSize:uint32_t -> If the reference table is not refTableSize big, fails. | 232 ReferenceCountTag = '?', // refTableSize:uint32_t -> If the reference table is not refTableSize big, fails. |
| 231 StringObjectTag = 's', // string:RawString -> new String(string) (ref) | 233 StringObjectTag = 's', // string:RawString -> new String(string) (ref) |
| 232 NumberObjectTag = 'n', // value:double -> new Number(value) (ref) | 234 NumberObjectTag = 'n', // value:double -> new Number(value) (ref) |
| 233 TrueObjectTag = 'y', // new Boolean(true) (ref) | 235 TrueObjectTag = 'y', // new Boolean(true) (ref) |
| 234 FalseObjectTag = 'x', // new Boolean(false) (ref) | 236 FalseObjectTag = 'x', // new Boolean(false) (ref) |
| 235 VersionTag = 0xFF // version:uint32_t -> Uses this as the file version. | 237 VersionTag = 0xFF // version:uint32_t -> Uses this as the file version. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 246 FloatArrayTag = 'f', | 248 FloatArrayTag = 'f', |
| 247 DoubleArrayTag = 'F', | 249 DoubleArrayTag = 'F', |
| 248 DataViewTag = '?' | 250 DataViewTag = '?' |
| 249 }; | 251 }; |
| 250 | 252 |
| 251 enum CryptoKeySubTag { | 253 enum CryptoKeySubTag { |
| 252 AesKeyTag = 1, | 254 AesKeyTag = 1, |
| 253 HmacKeyTag = 2, | 255 HmacKeyTag = 2, |
| 254 // ID 3 was used by RsaKeyTag, while still behind experimental flag. | 256 // ID 3 was used by RsaKeyTag, while still behind experimental flag. |
| 255 RsaHashedKeyTag = 4, | 257 RsaHashedKeyTag = 4, |
| 258 EcKeyTag = 5, | |
| 256 // Maximum allowed value is 255 | 259 // Maximum allowed value is 255 |
| 257 }; | 260 }; |
| 258 | 261 |
| 259 enum AssymetricCryptoKeyType { | 262 enum AssymetricCryptoKeyType { |
| 260 PublicKeyType = 1, | 263 PublicKeyType = 1, |
| 261 PrivateKeyType = 2, | 264 PrivateKeyType = 2, |
| 262 // Maximum allowed value is 2^32-1 | 265 // Maximum allowed value is 2^32-1 |
| 263 }; | 266 }; |
| 264 | 267 |
| 265 enum CryptoKeyAlgorithmTag { | 268 enum CryptoKeyAlgorithmTag { |
| 266 AesCbcTag = 1, | 269 AesCbcTag = 1, |
| 267 HmacTag = 2, | 270 HmacTag = 2, |
| 268 RsaSsaPkcs1v1_5Tag = 3, | 271 RsaSsaPkcs1v1_5Tag = 3, |
| 269 // ID 4 was used by RsaEs, while still behind experimental flag. | 272 // ID 4 was used by RsaEs, while still behind experimental flag. |
| 270 Sha1Tag = 5, | 273 Sha1Tag = 5, |
| 271 Sha256Tag = 6, | 274 Sha256Tag = 6, |
| 272 Sha384Tag = 7, | 275 Sha384Tag = 7, |
| 273 Sha512Tag = 8, | 276 Sha512Tag = 8, |
| 274 AesGcmTag = 9, | 277 AesGcmTag = 9, |
| 275 RsaOaepTag = 10, | 278 RsaOaepTag = 10, |
| 276 AesCtrTag = 11, | 279 AesCtrTag = 11, |
| 277 AesKwTag = 12, | 280 AesKwTag = 12, |
| 278 RsaPssTag = 13, | 281 RsaPssTag = 13, |
| 282 EcdsaTag = 14, | |
| 279 // Maximum allowed value is 2^32-1 | 283 // Maximum allowed value is 2^32-1 |
| 280 }; | 284 }; |
| 281 | 285 |
| 286 enum NamedCurveTag { | |
| 287 P256Tag = 1, | |
| 288 P384Tag = 2, | |
| 289 P521Tag = 3, | |
| 290 // Maximum allowed value is 2^32-1 | |
|
jww
2014/11/12 08:10:54
Okay, I'm feeling really ignorant here, but what d
eroman
2014/11/12 19:11:13
Perhaps the comment is not necessary.
My intent i
jww
2014/11/13 06:15:08
Got it. I actually didn't see that the other enums
| |
| 291 }; | |
| 292 | |
| 282 enum CryptoKeyUsage { | 293 enum CryptoKeyUsage { |
| 283 // Extractability is not a "usage" in the WebCryptoKeyUsages sense, however | 294 // Extractability is not a "usage" in the WebCryptoKeyUsages sense, however |
| 284 // it fits conveniently into this bitfield. | 295 // it fits conveniently into this bitfield. |
| 285 ExtractableUsage = 1 << 0, | 296 ExtractableUsage = 1 << 0, |
| 286 | 297 |
| 287 EncryptUsage = 1 << 1, | 298 EncryptUsage = 1 << 1, |
| 288 DecryptUsage = 1 << 2, | 299 DecryptUsage = 1 << 2, |
| 289 SignUsage = 1 << 3, | 300 SignUsage = 1 << 3, |
| 290 VerifyUsage = 1 << 4, | 301 VerifyUsage = 1 << 4, |
| 291 DeriveKeyUsage = 1 << 5, | 302 DeriveKeyUsage = 1 << 5, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 switch (key.algorithm().paramsType()) { | 523 switch (key.algorithm().paramsType()) { |
| 513 case WebCryptoKeyAlgorithmParamsTypeAes: | 524 case WebCryptoKeyAlgorithmParamsTypeAes: |
| 514 doWriteAesKey(key); | 525 doWriteAesKey(key); |
| 515 break; | 526 break; |
| 516 case WebCryptoKeyAlgorithmParamsTypeHmac: | 527 case WebCryptoKeyAlgorithmParamsTypeHmac: |
| 517 doWriteHmacKey(key); | 528 doWriteHmacKey(key); |
| 518 break; | 529 break; |
| 519 case WebCryptoKeyAlgorithmParamsTypeRsaHashed: | 530 case WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
| 520 doWriteRsaHashedKey(key); | 531 doWriteRsaHashedKey(key); |
| 521 break; | 532 break; |
| 533 case WebCryptoKeyAlgorithmParamsTypeEc: | |
| 534 doWriteEcKey(key); | |
| 535 break; | |
| 522 case WebCryptoKeyAlgorithmParamsTypeNone: | 536 case WebCryptoKeyAlgorithmParamsTypeNone: |
| 523 ASSERT_NOT_REACHED(); | 537 ASSERT_NOT_REACHED(); |
| 524 return false; | 538 return false; |
| 525 } | 539 } |
| 526 | 540 |
| 527 doWriteKeyUsages(key.usages(), key.extractable()); | 541 doWriteKeyUsages(key.usages(), key.extractable()); |
| 528 | 542 |
| 529 WebVector<uint8_t> keyData; | 543 WebVector<uint8_t> keyData; |
| 530 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData)) | 544 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData)) |
| 531 return false; | 545 return false; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 729 ASSERT(!(key.algorithm().aesParams()->lengthBits() % 8)); | 743 ASSERT(!(key.algorithm().aesParams()->lengthBits() % 8)); |
| 730 doWriteUint32(key.algorithm().aesParams()->lengthBits() / 8); | 744 doWriteUint32(key.algorithm().aesParams()->lengthBits() / 8); |
| 731 } | 745 } |
| 732 | 746 |
| 733 void doWriteRsaHashedKey(const WebCryptoKey& key) | 747 void doWriteRsaHashedKey(const WebCryptoKey& key) |
| 734 { | 748 { |
| 735 ASSERT(key.algorithm().rsaHashedParams()); | 749 ASSERT(key.algorithm().rsaHashedParams()); |
| 736 append(static_cast<uint8_t>(RsaHashedKeyTag)); | 750 append(static_cast<uint8_t>(RsaHashedKeyTag)); |
| 737 | 751 |
| 738 doWriteAlgorithmId(key.algorithm().id()); | 752 doWriteAlgorithmId(key.algorithm().id()); |
| 739 | 753 doWriteAsymmetricKeyType(key.type()); |
| 740 switch (key.type()) { | |
| 741 case WebCryptoKeyTypePublic: | |
| 742 doWriteUint32(PublicKeyType); | |
| 743 break; | |
| 744 case WebCryptoKeyTypePrivate: | |
| 745 doWriteUint32(PrivateKeyType); | |
| 746 break; | |
| 747 case WebCryptoKeyTypeSecret: | |
| 748 ASSERT_NOT_REACHED(); | |
| 749 } | |
| 750 | 754 |
| 751 const WebCryptoRsaHashedKeyAlgorithmParams* params = key.algorithm().rsa HashedParams(); | 755 const WebCryptoRsaHashedKeyAlgorithmParams* params = key.algorithm().rsa HashedParams(); |
| 752 doWriteUint32(params->modulusLengthBits()); | 756 doWriteUint32(params->modulusLengthBits()); |
| 753 doWriteUint32(params->publicExponent().size()); | 757 doWriteUint32(params->publicExponent().size()); |
| 754 append(params->publicExponent().data(), params->publicExponent().size()) ; | 758 append(params->publicExponent().data(), params->publicExponent().size()) ; |
| 755 doWriteAlgorithmId(key.algorithm().rsaHashedParams()->hash().id()); | 759 doWriteAlgorithmId(params->hash().id()); |
| 760 } | |
| 761 | |
| 762 void doWriteEcKey(const WebCryptoKey& key) | |
| 763 { | |
| 764 ASSERT(key.algorithm().ecParams()); | |
| 765 append(static_cast<uint8_t>(EcKeyTag)); | |
| 766 | |
| 767 doWriteAlgorithmId(key.algorithm().id()); | |
| 768 doWriteAsymmetricKeyType(key.type()); | |
| 769 doWriteNamedCurve(key.algorithm().ecParams()->namedCurve()); | |
| 756 } | 770 } |
| 757 | 771 |
| 758 void doWriteAlgorithmId(WebCryptoAlgorithmId id) | 772 void doWriteAlgorithmId(WebCryptoAlgorithmId id) |
| 759 { | 773 { |
| 760 switch (id) { | 774 switch (id) { |
| 761 case WebCryptoAlgorithmIdAesCbc: | 775 case WebCryptoAlgorithmIdAesCbc: |
| 762 return doWriteUint32(AesCbcTag); | 776 return doWriteUint32(AesCbcTag); |
| 763 case WebCryptoAlgorithmIdHmac: | 777 case WebCryptoAlgorithmIdHmac: |
| 764 return doWriteUint32(HmacTag); | 778 return doWriteUint32(HmacTag); |
| 765 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: | 779 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 766 return doWriteUint32(RsaSsaPkcs1v1_5Tag); | 780 return doWriteUint32(RsaSsaPkcs1v1_5Tag); |
| 767 case WebCryptoAlgorithmIdSha1: | 781 case WebCryptoAlgorithmIdSha1: |
| 768 return doWriteUint32(Sha1Tag); | 782 return doWriteUint32(Sha1Tag); |
| 769 case WebCryptoAlgorithmIdSha256: | 783 case WebCryptoAlgorithmIdSha256: |
| 770 return doWriteUint32(Sha256Tag); | 784 return doWriteUint32(Sha256Tag); |
| 771 case WebCryptoAlgorithmIdSha384: | 785 case WebCryptoAlgorithmIdSha384: |
| 772 return doWriteUint32(Sha384Tag); | 786 return doWriteUint32(Sha384Tag); |
| 773 case WebCryptoAlgorithmIdSha512: | 787 case WebCryptoAlgorithmIdSha512: |
| 774 return doWriteUint32(Sha512Tag); | 788 return doWriteUint32(Sha512Tag); |
| 775 case WebCryptoAlgorithmIdAesGcm: | 789 case WebCryptoAlgorithmIdAesGcm: |
| 776 return doWriteUint32(AesGcmTag); | 790 return doWriteUint32(AesGcmTag); |
| 777 case WebCryptoAlgorithmIdRsaOaep: | 791 case WebCryptoAlgorithmIdRsaOaep: |
| 778 return doWriteUint32(RsaOaepTag); | 792 return doWriteUint32(RsaOaepTag); |
| 779 case WebCryptoAlgorithmIdAesCtr: | 793 case WebCryptoAlgorithmIdAesCtr: |
| 780 return doWriteUint32(AesCtrTag); | 794 return doWriteUint32(AesCtrTag); |
| 781 case WebCryptoAlgorithmIdAesKw: | 795 case WebCryptoAlgorithmIdAesKw: |
| 782 return doWriteUint32(AesKwTag); | 796 return doWriteUint32(AesKwTag); |
| 783 case WebCryptoAlgorithmIdRsaPss: | 797 case WebCryptoAlgorithmIdRsaPss: |
| 784 return doWriteUint32(RsaPssTag); | 798 return doWriteUint32(RsaPssTag); |
| 799 case WebCryptoAlgorithmIdEcdsa: | |
| 800 return doWriteUint32(EcdsaTag); | |
| 785 } | 801 } |
| 786 ASSERT_NOT_REACHED(); | 802 ASSERT_NOT_REACHED(); |
| 787 } | 803 } |
| 804 | |
| 805 void doWriteAsymmetricKeyType(WebCryptoKeyType keyType) | |
| 806 { | |
| 807 switch (keyType) { | |
| 808 case WebCryptoKeyTypePublic: | |
| 809 doWriteUint32(PublicKeyType); | |
| 810 break; | |
| 811 case WebCryptoKeyTypePrivate: | |
| 812 doWriteUint32(PrivateKeyType); | |
| 813 break; | |
| 814 case WebCryptoKeyTypeSecret: | |
| 815 ASSERT_NOT_REACHED(); | |
| 816 } | |
| 817 } | |
| 818 | |
| 819 void doWriteNamedCurve(WebCryptoNamedCurve namedCurve) | |
| 820 { | |
| 821 switch (namedCurve) { | |
| 822 case WebCryptoNamedCurveP256: | |
| 823 return doWriteUint32(P256Tag); | |
| 824 case WebCryptoNamedCurveP384: | |
| 825 return doWriteUint32(P384Tag); | |
| 826 case WebCryptoNamedCurveP521: | |
| 827 return doWriteUint32(P521Tag); | |
| 828 } | |
| 829 ASSERT_NOT_REACHED(); | |
| 830 } | |
| 788 | 831 |
| 789 void doWriteKeyUsages(const WebCryptoKeyUsageMask usages, bool extractable) | 832 void doWriteKeyUsages(const WebCryptoKeyUsageMask usages, bool extractable) |
| 790 { | 833 { |
| 791 // Reminder to update this when adding new key usages. | 834 // Reminder to update this when adding new key usages. |
| 792 COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); | 835 COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
| 793 | 836 |
| 794 uint32_t value = 0; | 837 uint32_t value = 0; |
| 795 | 838 |
| 796 if (extractable) | 839 if (extractable) |
| 797 value |= ExtractableUsage; | 840 value |= ExtractableUsage; |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2252 return false; | 2295 return false; |
| 2253 break; | 2296 break; |
| 2254 case HmacKeyTag: | 2297 case HmacKeyTag: |
| 2255 if (!doReadHmacKey(algorithm, type)) | 2298 if (!doReadHmacKey(algorithm, type)) |
| 2256 return false; | 2299 return false; |
| 2257 break; | 2300 break; |
| 2258 case RsaHashedKeyTag: | 2301 case RsaHashedKeyTag: |
| 2259 if (!doReadRsaHashedKey(algorithm, type)) | 2302 if (!doReadRsaHashedKey(algorithm, type)) |
| 2260 return false; | 2303 return false; |
| 2261 break; | 2304 break; |
| 2305 case EcKeyTag: | |
| 2306 if (!doReadEcKey(algorithm, type)) | |
| 2307 return false; | |
| 2308 break; | |
| 2262 default: | 2309 default: |
| 2263 return false; | 2310 return false; |
| 2264 } | 2311 } |
| 2265 | 2312 |
| 2266 WebCryptoKeyUsageMask usages; | 2313 WebCryptoKeyUsageMask usages; |
| 2267 bool extractable; | 2314 bool extractable; |
| 2268 if (!doReadKeyUsages(usages, extractable)) | 2315 if (!doReadKeyUsages(usages, extractable)) |
| 2269 return false; | 2316 return false; |
| 2270 | 2317 |
| 2271 uint32_t keyDataLength; | 2318 uint32_t keyDataLength; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2419 type = WebCryptoKeyTypeSecret; | 2466 type = WebCryptoKeyTypeSecret; |
| 2420 return !algorithm.isNull(); | 2467 return !algorithm.isNull(); |
| 2421 } | 2468 } |
| 2422 | 2469 |
| 2423 bool doReadRsaHashedKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type) | 2470 bool doReadRsaHashedKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type) |
| 2424 { | 2471 { |
| 2425 WebCryptoAlgorithmId id; | 2472 WebCryptoAlgorithmId id; |
| 2426 if (!doReadAlgorithmId(id)) | 2473 if (!doReadAlgorithmId(id)) |
| 2427 return false; | 2474 return false; |
| 2428 | 2475 |
| 2429 uint32_t rawType; | 2476 if (!doReadAsymmetricKeyType(type)) |
| 2430 if (!doReadUint32(&rawType)) | |
| 2431 return false; | 2477 return false; |
| 2432 | 2478 |
| 2433 switch (static_cast<AssymetricCryptoKeyType>(rawType)) { | |
| 2434 case PublicKeyType: | |
| 2435 type = WebCryptoKeyTypePublic; | |
| 2436 break; | |
| 2437 case PrivateKeyType: | |
| 2438 type = WebCryptoKeyTypePrivate; | |
| 2439 break; | |
| 2440 default: | |
| 2441 return false; | |
| 2442 } | |
| 2443 | |
| 2444 uint32_t modulusLengthBits; | 2479 uint32_t modulusLengthBits; |
| 2445 if (!doReadUint32(&modulusLengthBits)) | 2480 if (!doReadUint32(&modulusLengthBits)) |
| 2446 return false; | 2481 return false; |
| 2447 | 2482 |
| 2448 uint32_t publicExponentSize; | 2483 uint32_t publicExponentSize; |
| 2449 if (!doReadUint32(&publicExponentSize)) | 2484 if (!doReadUint32(&publicExponentSize)) |
| 2450 return false; | 2485 return false; |
| 2451 | 2486 |
| 2452 if (m_position + publicExponentSize > m_length) | 2487 if (m_position + publicExponentSize > m_length) |
| 2453 return false; | 2488 return false; |
| 2454 | 2489 |
| 2455 const uint8_t* publicExponent = m_buffer + m_position; | 2490 const uint8_t* publicExponent = m_buffer + m_position; |
| 2456 m_position += publicExponentSize; | 2491 m_position += publicExponentSize; |
| 2457 | 2492 |
| 2458 WebCryptoAlgorithmId hash; | 2493 WebCryptoAlgorithmId hash; |
| 2459 if (!doReadAlgorithmId(hash)) | 2494 if (!doReadAlgorithmId(hash)) |
| 2460 return false; | 2495 return false; |
| 2461 algorithm = WebCryptoKeyAlgorithm::createRsaHashed(id, modulusLengthBits , publicExponent, publicExponentSize, hash); | 2496 algorithm = WebCryptoKeyAlgorithm::createRsaHashed(id, modulusLengthBits , publicExponent, publicExponentSize, hash); |
| 2462 | 2497 |
| 2463 return !algorithm.isNull(); | 2498 return !algorithm.isNull(); |
| 2464 } | 2499 } |
| 2465 | 2500 |
| 2501 bool doReadEcKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type) | |
| 2502 { | |
| 2503 WebCryptoAlgorithmId id; | |
| 2504 if (!doReadAlgorithmId(id)) | |
| 2505 return false; | |
| 2506 | |
| 2507 if (!doReadAsymmetricKeyType(type)) | |
| 2508 return false; | |
| 2509 | |
| 2510 WebCryptoNamedCurve namedCurve; | |
| 2511 if (!doReadNamedCurve(namedCurve)) | |
| 2512 return false; | |
| 2513 | |
| 2514 algorithm = WebCryptoKeyAlgorithm::createEc(id, namedCurve); | |
| 2515 return !algorithm.isNull(); | |
| 2516 } | |
| 2517 | |
| 2466 bool doReadAlgorithmId(WebCryptoAlgorithmId& id) | 2518 bool doReadAlgorithmId(WebCryptoAlgorithmId& id) |
| 2467 { | 2519 { |
| 2468 uint32_t rawId; | 2520 uint32_t rawId; |
| 2469 if (!doReadUint32(&rawId)) | 2521 if (!doReadUint32(&rawId)) |
| 2470 return false; | 2522 return false; |
| 2471 | 2523 |
| 2472 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { | 2524 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { |
| 2473 case AesCbcTag: | 2525 case AesCbcTag: |
| 2474 id = WebCryptoAlgorithmIdAesCbc; | 2526 id = WebCryptoAlgorithmIdAesCbc; |
| 2475 return true; | 2527 return true; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 2499 return true; | 2551 return true; |
| 2500 case AesCtrTag: | 2552 case AesCtrTag: |
| 2501 id = WebCryptoAlgorithmIdAesCtr; | 2553 id = WebCryptoAlgorithmIdAesCtr; |
| 2502 return true; | 2554 return true; |
| 2503 case AesKwTag: | 2555 case AesKwTag: |
| 2504 id = WebCryptoAlgorithmIdAesKw; | 2556 id = WebCryptoAlgorithmIdAesKw; |
| 2505 return true; | 2557 return true; |
| 2506 case RsaPssTag: | 2558 case RsaPssTag: |
| 2507 id = WebCryptoAlgorithmIdRsaPss; | 2559 id = WebCryptoAlgorithmIdRsaPss; |
| 2508 return true; | 2560 return true; |
| 2561 case EcdsaTag: | |
| 2562 id = WebCryptoAlgorithmIdEcdsa; | |
| 2563 return true; | |
| 2509 } | 2564 } |
| 2510 | 2565 |
| 2511 return false; | 2566 return false; |
| 2567 } | |
| 2568 | |
| 2569 bool doReadAsymmetricKeyType(WebCryptoKeyType& type) | |
| 2570 { | |
| 2571 uint32_t rawType; | |
| 2572 if (!doReadUint32(&rawType)) | |
| 2573 return false; | |
| 2574 | |
| 2575 switch (static_cast<AssymetricCryptoKeyType>(rawType)) { | |
| 2576 case PublicKeyType: | |
| 2577 type = WebCryptoKeyTypePublic; | |
| 2578 return true; | |
| 2579 case PrivateKeyType: | |
| 2580 type = WebCryptoKeyTypePrivate; | |
| 2581 return true; | |
| 2582 } | |
| 2583 | |
| 2584 return false; | |
| 2585 } | |
| 2586 | |
| 2587 bool doReadNamedCurve(WebCryptoNamedCurve& namedCurve) | |
| 2588 { | |
| 2589 uint32_t rawName; | |
| 2590 if (!doReadUint32(&rawName)) | |
| 2591 return false; | |
| 2592 | |
| 2593 switch (static_cast<NamedCurveTag>(rawName)) { | |
| 2594 case P256Tag: | |
| 2595 namedCurve = WebCryptoNamedCurveP256; | |
| 2596 return true; | |
| 2597 case P384Tag: | |
| 2598 namedCurve = WebCryptoNamedCurveP384; | |
| 2599 return true; | |
| 2600 case P521Tag: | |
| 2601 namedCurve = WebCryptoNamedCurveP521; | |
| 2602 return true; | |
| 2603 } | |
| 2604 | |
| 2605 return false; | |
| 2512 } | 2606 } |
| 2513 | 2607 |
| 2514 bool doReadKeyUsages(WebCryptoKeyUsageMask& usages, bool& extractable) | 2608 bool doReadKeyUsages(WebCryptoKeyUsageMask& usages, bool& extractable) |
| 2515 { | 2609 { |
| 2516 // Reminder to update this when adding new key usages. | 2610 // Reminder to update this when adding new key usages. |
| 2517 COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); | 2611 COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
| 2518 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU sage | DeriveBitsUsage; | 2612 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU sage | DeriveBitsUsage; |
| 2519 | 2613 |
| 2520 uint32_t rawUsages; | 2614 uint32_t rawUsages; |
| 2521 if (!doReadUint32(&rawUsages)) | 2615 if (!doReadUint32(&rawUsages)) |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3065 // If the allocated memory was not registered before, then this class is lik ely | 3159 // If the allocated memory was not registered before, then this class is lik ely |
| 3066 // used in a context other then Worker's onmessage environment and the prese nce of | 3160 // used in a context other then Worker's onmessage environment and the prese nce of |
| 3067 // current v8 context is not guaranteed. Avoid calling v8 then. | 3161 // current v8 context is not guaranteed. Avoid calling v8 then. |
| 3068 if (m_externallyAllocatedMemory) { | 3162 if (m_externallyAllocatedMemory) { |
| 3069 ASSERT(v8::Isolate::GetCurrent()); | 3163 ASSERT(v8::Isolate::GetCurrent()); |
| 3070 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 3164 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
| 3071 } | 3165 } |
| 3072 } | 3166 } |
| 3073 | 3167 |
| 3074 } // namespace blink | 3168 } // namespace blink |
| OLD | NEW |