| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 #endif | 63 #endif |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Must be sorted by length, and then by reverse string. | 66 // Must be sorted by length, and then by reverse string. |
| 67 // Also all names must be upper case ASCII. | 67 // Also all names must be upper case ASCII. |
| 68 const AlgorithmNameMapping algorithmNameMappings[] = { | 68 const AlgorithmNameMapping algorithmNameMappings[] = { |
| 69 {"HMAC", 4, WebCryptoAlgorithmIdHmac}, | 69 {"HMAC", 4, WebCryptoAlgorithmIdHmac}, |
| 70 {"ECDH", 4, WebCryptoAlgorithmIdEcdh}, | 70 {"ECDH", 4, WebCryptoAlgorithmIdEcdh}, |
| 71 {"SHA-1", 5, WebCryptoAlgorithmIdSha1}, | 71 {"SHA-1", 5, WebCryptoAlgorithmIdSha1}, |
| 72 {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa}, | 72 {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa}, |
| 73 {"PBKDF2", 6, WebCryptoAlgorithmIdPbkdf2}, |
| 73 {"AES-KW", 6, WebCryptoAlgorithmIdAesKw}, | 74 {"AES-KW", 6, WebCryptoAlgorithmIdAesKw}, |
| 74 {"SHA-512", 7, WebCryptoAlgorithmIdSha512}, | 75 {"SHA-512", 7, WebCryptoAlgorithmIdSha512}, |
| 75 {"SHA-384", 7, WebCryptoAlgorithmIdSha384}, | 76 {"SHA-384", 7, WebCryptoAlgorithmIdSha384}, |
| 76 {"SHA-256", 7, WebCryptoAlgorithmIdSha256}, | 77 {"SHA-256", 7, WebCryptoAlgorithmIdSha256}, |
| 77 {"AES-CBC", 7, WebCryptoAlgorithmIdAesCbc}, | 78 {"AES-CBC", 7, WebCryptoAlgorithmIdAesCbc}, |
| 78 {"AES-GCM", 7, WebCryptoAlgorithmIdAesGcm}, | 79 {"AES-GCM", 7, WebCryptoAlgorithmIdAesGcm}, |
| 79 {"AES-CTR", 7, WebCryptoAlgorithmIdAesCtr}, | 80 {"AES-CTR", 7, WebCryptoAlgorithmIdAesCtr}, |
| 80 {"RSA-PSS", 7, WebCryptoAlgorithmIdRsaPss}, | 81 {"RSA-PSS", 7, WebCryptoAlgorithmIdRsaPss}, |
| 81 {"RSA-OAEP", 8, WebCryptoAlgorithmIdRsaOaep}, | 82 {"RSA-OAEP", 8, WebCryptoAlgorithmIdRsaOaep}, |
| 82 {"RSASSA-PKCS1-V1_5", 17, WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, | 83 {"RSASSA-PKCS1-V1_5", 17, WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 | 751 |
| 751 CryptoKey* cryptoKey = V8CryptoKey::toImplWithTypeCheck(raw.isolate(), v8Val
ue); | 752 CryptoKey* cryptoKey = V8CryptoKey::toImplWithTypeCheck(raw.isolate(), v8Val
ue); |
| 752 if (!cryptoKey) { | 753 if (!cryptoKey) { |
| 753 setTypeError(context.toString("public", "Must be a CryptoKey"), error); | 754 setTypeError(context.toString("public", "Must be a CryptoKey"), error); |
| 754 return false; | 755 return false; |
| 755 } | 756 } |
| 756 | 757 |
| 757 params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); | 758 params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); |
| 758 return true; | 759 return true; |
| 759 } | 760 } |
| 761 // dictionary Pbkdf2Params : Algorithm { |
| 762 // required BufferSource salt; |
| 763 // [EnforceRange] required unsigned long iterations; |
| 764 // required HashAlgorithmIdentifier hash; |
| 765 // }; |
| 766 bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
params, const ErrorContext& context, AlgorithmError* error) |
| 767 { |
| 768 BufferSource saltBufferSource; |
| 769 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) |
| 770 return false; |
| 771 |
| 772 DOMArrayPiece salt(saltBufferSource); |
| 773 |
| 774 uint32_t iterations; |
| 775 if (!getUint32(raw, "iterations", iterations, context, error)) |
| 776 return false; |
| 777 |
| 778 WebCryptoAlgorithm hash; |
| 779 if (!parseHash(raw, hash, context, error)) |
| 780 return false; |
| 781 params = adoptPtr(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteLen
gth(), iterations)); |
| 782 return true; |
| 783 } |
| 760 | 784 |
| 761 // Defined by the WebCrypto spec as: | 785 // Defined by the WebCrypto spec as: |
| 762 // | 786 // |
| 763 // dictionary AesDerivedKeyParams : Algorithm { | 787 // dictionary AesDerivedKeyParams : Algorithm { |
| 764 // [EnforceRange] required unsigned short length; | 788 // [EnforceRange] required unsigned short length; |
| 765 // }; | 789 // }; |
| 766 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) | 790 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
| 767 { | 791 { |
| 768 uint16_t length; | 792 uint16_t length; |
| 769 if (!getUint16(raw, "length", length, context, error)) | 793 if (!getUint16(raw, "length", length, context, error)) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 return parseEcKeyGenParams(raw, params, context, error); | 840 return parseEcKeyGenParams(raw, params, context, error); |
| 817 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: | 841 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: |
| 818 context.add("EcKeyImportParams"); | 842 context.add("EcKeyImportParams"); |
| 819 return parseEcKeyImportParams(raw, params, context, error); | 843 return parseEcKeyImportParams(raw, params, context, error); |
| 820 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: | 844 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: |
| 821 context.add("EcdhKeyDeriveParams"); | 845 context.add("EcdhKeyDeriveParams"); |
| 822 return parseEcdhKeyDeriveParams(raw, params, context, error); | 846 return parseEcdhKeyDeriveParams(raw, params, context, error); |
| 823 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: | 847 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: |
| 824 context.add("AesDerivedKeyParams"); | 848 context.add("AesDerivedKeyParams"); |
| 825 return parseAesDerivedKeyParams(raw, params, context, error); | 849 return parseAesDerivedKeyParams(raw, params, context, error); |
| 850 case WebCryptoAlgorithmParamsTypePbkdf2Params: |
| 851 context.add("Pbkdf2Params"); |
| 852 return parsePbkdf2Params(raw, params, context, error); |
| 826 } | 853 } |
| 827 ASSERT_NOT_REACHED(); | 854 ASSERT_NOT_REACHED(); |
| 828 return false; | 855 return false; |
| 829 } | 856 } |
| 830 | 857 |
| 831 const char* operationToString(WebCryptoOperation op) | 858 const char* operationToString(WebCryptoOperation op) |
| 832 { | 859 { |
| 833 switch (op) { | 860 switch (op) { |
| 834 case WebCryptoOperationEncrypt: | 861 case WebCryptoOperationEncrypt: |
| 835 return "encrypt"; | 862 return "encrypt"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 } | 940 } |
| 914 | 941 |
| 915 } // namespace | 942 } // namespace |
| 916 | 943 |
| 917 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) | 944 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) |
| 918 { | 945 { |
| 919 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 946 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
| 920 } | 947 } |
| 921 | 948 |
| 922 } // namespace blink | 949 } // namespace blink |
| OLD | NEW |