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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // it fits conveniently into this bitfield. | 286 // it fits conveniently into this bitfield. |
287 ExtractableUsage = 1 << 0, | 287 ExtractableUsage = 1 << 0, |
288 | 288 |
289 EncryptUsage = 1 << 1, | 289 EncryptUsage = 1 << 1, |
290 DecryptUsage = 1 << 2, | 290 DecryptUsage = 1 << 2, |
291 SignUsage = 1 << 3, | 291 SignUsage = 1 << 3, |
292 VerifyUsage = 1 << 4, | 292 VerifyUsage = 1 << 4, |
293 DeriveKeyUsage = 1 << 5, | 293 DeriveKeyUsage = 1 << 5, |
294 WrapKeyUsage = 1 << 6, | 294 WrapKeyUsage = 1 << 6, |
295 UnwrapKeyUsage = 1 << 7, | 295 UnwrapKeyUsage = 1 << 7, |
| 296 DeriveBitsUsage = 1 << 8, |
296 // Maximum allowed value is 1 << 31 | 297 // Maximum allowed value is 1 << 31 |
297 }; | 298 }; |
298 | 299 |
299 static bool shouldCheckForCycles(int depth) | 300 static bool shouldCheckForCycles(int depth) |
300 { | 301 { |
301 ASSERT(depth >= 0); | 302 ASSERT(depth >= 0); |
302 // Since we are not required to spot the cycle as soon as it | 303 // Since we are not required to spot the cycle as soon as it |
303 // happens we can check for cycles only when the current depth | 304 // happens we can check for cycles only when the current depth |
304 // is a power of two. | 305 // is a power of two. |
305 return !(depth & (depth - 1)); | 306 return !(depth & (depth - 1)); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 return doWriteUint32(AesCtrTag); | 787 return doWriteUint32(AesCtrTag); |
787 case blink::WebCryptoAlgorithmIdAesKw: | 788 case blink::WebCryptoAlgorithmIdAesKw: |
788 return doWriteUint32(AesKwTag); | 789 return doWriteUint32(AesKwTag); |
789 } | 790 } |
790 ASSERT_NOT_REACHED(); | 791 ASSERT_NOT_REACHED(); |
791 } | 792 } |
792 | 793 |
793 void doWriteKeyUsages(const blink::WebCryptoKeyUsageMask usages, bool extrac
table) | 794 void doWriteKeyUsages(const blink::WebCryptoKeyUsageMask usages, bool extrac
table) |
794 { | 795 { |
795 // Reminder to update this when adding new key usages. | 796 // Reminder to update this when adding new key usages. |
796 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 6) + 1, UpdateMe); | 797 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
797 | 798 |
798 uint32_t value = 0; | 799 uint32_t value = 0; |
799 | 800 |
800 if (extractable) | 801 if (extractable) |
801 value |= ExtractableUsage; | 802 value |= ExtractableUsage; |
802 | 803 |
803 if (usages & blink::WebCryptoKeyUsageEncrypt) | 804 if (usages & blink::WebCryptoKeyUsageEncrypt) |
804 value |= EncryptUsage; | 805 value |= EncryptUsage; |
805 if (usages & blink::WebCryptoKeyUsageDecrypt) | 806 if (usages & blink::WebCryptoKeyUsageDecrypt) |
806 value |= DecryptUsage; | 807 value |= DecryptUsage; |
807 if (usages & blink::WebCryptoKeyUsageSign) | 808 if (usages & blink::WebCryptoKeyUsageSign) |
808 value |= SignUsage; | 809 value |= SignUsage; |
809 if (usages & blink::WebCryptoKeyUsageVerify) | 810 if (usages & blink::WebCryptoKeyUsageVerify) |
810 value |= VerifyUsage; | 811 value |= VerifyUsage; |
811 if (usages & blink::WebCryptoKeyUsageDeriveKey) | 812 if (usages & blink::WebCryptoKeyUsageDeriveKey) |
812 value |= DeriveKeyUsage; | 813 value |= DeriveKeyUsage; |
813 if (usages & blink::WebCryptoKeyUsageWrapKey) | 814 if (usages & blink::WebCryptoKeyUsageWrapKey) |
814 value |= WrapKeyUsage; | 815 value |= WrapKeyUsage; |
815 if (usages & blink::WebCryptoKeyUsageUnwrapKey) | 816 if (usages & blink::WebCryptoKeyUsageUnwrapKey) |
816 value |= UnwrapKeyUsage; | 817 value |= UnwrapKeyUsage; |
| 818 if (usages & blink::WebCryptoKeyUsageDeriveBits) |
| 819 value |= DeriveBitsUsage; |
817 | 820 |
818 doWriteUint32(value); | 821 doWriteUint32(value); |
819 } | 822 } |
820 | 823 |
821 int bytesNeededToWireEncode(uint32_t value) | 824 int bytesNeededToWireEncode(uint32_t value) |
822 { | 825 { |
823 int bytes = 1; | 826 int bytes = 1; |
824 while (true) { | 827 while (true) { |
825 value >>= varIntShift; | 828 value >>= varIntShift; |
826 if (!value) | 829 if (!value) |
(...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2501 id = blink::WebCryptoAlgorithmIdAesKw; | 2504 id = blink::WebCryptoAlgorithmIdAesKw; |
2502 return true; | 2505 return true; |
2503 } | 2506 } |
2504 | 2507 |
2505 return false; | 2508 return false; |
2506 } | 2509 } |
2507 | 2510 |
2508 bool doReadKeyUsages(blink::WebCryptoKeyUsageMask& usages, bool& extractable
) | 2511 bool doReadKeyUsages(blink::WebCryptoKeyUsageMask& usages, bool& extractable
) |
2509 { | 2512 { |
2510 // Reminder to update this when adding new key usages. | 2513 // Reminder to update this when adding new key usages. |
2511 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 6) + 1, UpdateMe); | 2514 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
2512 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec
ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU
sage; | 2515 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec
ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU
sage | DeriveBitsUsage; |
2513 | 2516 |
2514 uint32_t rawUsages; | 2517 uint32_t rawUsages; |
2515 if (!doReadUint32(&rawUsages)) | 2518 if (!doReadUint32(&rawUsages)) |
2516 return false; | 2519 return false; |
2517 | 2520 |
2518 // Make sure it doesn't contain an unrecognized usage value. | 2521 // Make sure it doesn't contain an unrecognized usage value. |
2519 if (rawUsages & ~allPossibleUsages) | 2522 if (rawUsages & ~allPossibleUsages) |
2520 return false; | 2523 return false; |
2521 | 2524 |
2522 usages = 0; | 2525 usages = 0; |
2523 | 2526 |
2524 extractable = rawUsages & ExtractableUsage; | 2527 extractable = rawUsages & ExtractableUsage; |
2525 | 2528 |
2526 if (rawUsages & EncryptUsage) | 2529 if (rawUsages & EncryptUsage) |
2527 usages |= blink::WebCryptoKeyUsageEncrypt; | 2530 usages |= blink::WebCryptoKeyUsageEncrypt; |
2528 if (rawUsages & DecryptUsage) | 2531 if (rawUsages & DecryptUsage) |
2529 usages |= blink::WebCryptoKeyUsageDecrypt; | 2532 usages |= blink::WebCryptoKeyUsageDecrypt; |
2530 if (rawUsages & SignUsage) | 2533 if (rawUsages & SignUsage) |
2531 usages |= blink::WebCryptoKeyUsageSign; | 2534 usages |= blink::WebCryptoKeyUsageSign; |
2532 if (rawUsages & VerifyUsage) | 2535 if (rawUsages & VerifyUsage) |
2533 usages |= blink::WebCryptoKeyUsageVerify; | 2536 usages |= blink::WebCryptoKeyUsageVerify; |
2534 if (rawUsages & DeriveKeyUsage) | 2537 if (rawUsages & DeriveKeyUsage) |
2535 usages |= blink::WebCryptoKeyUsageDeriveKey; | 2538 usages |= blink::WebCryptoKeyUsageDeriveKey; |
2536 if (rawUsages & WrapKeyUsage) | 2539 if (rawUsages & WrapKeyUsage) |
2537 usages |= blink::WebCryptoKeyUsageWrapKey; | 2540 usages |= blink::WebCryptoKeyUsageWrapKey; |
2538 if (rawUsages & UnwrapKeyUsage) | 2541 if (rawUsages & UnwrapKeyUsage) |
2539 usages |= blink::WebCryptoKeyUsageUnwrapKey; | 2542 usages |= blink::WebCryptoKeyUsageUnwrapKey; |
| 2543 if (rawUsages & DeriveBitsUsage) |
| 2544 usages |= blink::WebCryptoKeyUsageDeriveBits; |
2540 | 2545 |
2541 return true; | 2546 return true; |
2542 } | 2547 } |
2543 | 2548 |
2544 const uint8_t* m_buffer; | 2549 const uint8_t* m_buffer; |
2545 const unsigned m_length; | 2550 const unsigned m_length; |
2546 unsigned m_position; | 2551 unsigned m_position; |
2547 uint32_t m_version; | 2552 uint32_t m_version; |
2548 v8::Isolate* m_isolate; | 2553 v8::Isolate* m_isolate; |
2549 const WebBlobInfoArray* m_blobInfo; | 2554 const WebBlobInfoArray* m_blobInfo; |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3054 // If the allocated memory was not registered before, then this class is lik
ely | 3059 // If the allocated memory was not registered before, then this class is lik
ely |
3055 // used in a context other then Worker's onmessage environment and the prese
nce of | 3060 // used in a context other then Worker's onmessage environment and the prese
nce of |
3056 // current v8 context is not guaranteed. Avoid calling v8 then. | 3061 // current v8 context is not guaranteed. Avoid calling v8 then. |
3057 if (m_externallyAllocatedMemory) { | 3062 if (m_externallyAllocatedMemory) { |
3058 ASSERT(v8::Isolate::GetCurrent()); | 3063 ASSERT(v8::Isolate::GetCurrent()); |
3059 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 3064 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
3060 } | 3065 } |
3061 } | 3066 } |
3062 | 3067 |
3063 } // namespace WebCore | 3068 } // namespace WebCore |
OLD | NEW |