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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 {"HKDF", 4, WebCryptoAlgorithmIdHkdf}, | 70 {"HKDF", 4, WebCryptoAlgorithmIdHkdf}, |
71 {"ECDH", 4, WebCryptoAlgorithmIdEcdh}, | 71 {"ECDH", 4, WebCryptoAlgorithmIdEcdh}, |
72 {"SHA-1", 5, WebCryptoAlgorithmIdSha1}, | 72 {"SHA-1", 5, WebCryptoAlgorithmIdSha1}, |
73 {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa}, | 73 {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa}, |
| 74 {"PBKDF2", 6, WebCryptoAlgorithmIdPbkdf2}, |
74 {"AES-KW", 6, WebCryptoAlgorithmIdAesKw}, | 75 {"AES-KW", 6, WebCryptoAlgorithmIdAesKw}, |
75 {"SHA-512", 7, WebCryptoAlgorithmIdSha512}, | 76 {"SHA-512", 7, WebCryptoAlgorithmIdSha512}, |
76 {"SHA-384", 7, WebCryptoAlgorithmIdSha384}, | 77 {"SHA-384", 7, WebCryptoAlgorithmIdSha384}, |
77 {"SHA-256", 7, WebCryptoAlgorithmIdSha256}, | 78 {"SHA-256", 7, WebCryptoAlgorithmIdSha256}, |
78 {"AES-CBC", 7, WebCryptoAlgorithmIdAesCbc}, | 79 {"AES-CBC", 7, WebCryptoAlgorithmIdAesCbc}, |
79 {"AES-GCM", 7, WebCryptoAlgorithmIdAesGcm}, | 80 {"AES-GCM", 7, WebCryptoAlgorithmIdAesGcm}, |
80 {"AES-CTR", 7, WebCryptoAlgorithmIdAesCtr}, | 81 {"AES-CTR", 7, WebCryptoAlgorithmIdAesCtr}, |
81 {"RSA-PSS", 7, WebCryptoAlgorithmIdRsaPss}, | 82 {"RSA-PSS", 7, WebCryptoAlgorithmIdRsaPss}, |
82 {"RSA-OAEP", 8, WebCryptoAlgorithmIdRsaOaep}, | 83 {"RSA-OAEP", 8, WebCryptoAlgorithmIdRsaOaep}, |
83 {"RSASSA-PKCS1-V1_5", 17, WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, | 84 {"RSASSA-PKCS1-V1_5", 17, WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 setTypeError(context.toString("public", "Must be a CryptoKey"), error); | 755 setTypeError(context.toString("public", "Must be a CryptoKey"), error); |
755 return false; | 756 return false; |
756 } | 757 } |
757 | 758 |
758 params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); | 759 params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); |
759 return true; | 760 return true; |
760 } | 761 } |
761 | 762 |
762 // Defined by the WebCrypto spec as: | 763 // Defined by the WebCrypto spec as: |
763 // | 764 // |
| 765 // dictionary Pbkdf2Params : Algorithm { |
| 766 // required BufferSource salt; |
| 767 // [EnforceRange] required unsigned long iterations; |
| 768 // required HashAlgorithmIdentifier hash; |
| 769 // }; |
| 770 bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
params, const ErrorContext& context, AlgorithmError* error) |
| 771 { |
| 772 BufferSource saltBufferSource; |
| 773 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) |
| 774 return false; |
| 775 |
| 776 DOMArrayPiece salt(saltBufferSource); |
| 777 |
| 778 uint32_t iterations; |
| 779 if (!getUint32(raw, "iterations", iterations, context, error)) |
| 780 return false; |
| 781 |
| 782 WebCryptoAlgorithm hash; |
| 783 if (!parseHash(raw, hash, context, error)) |
| 784 return false; |
| 785 params = adoptPtr(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteLen
gth(), iterations)); |
| 786 return true; |
| 787 } |
| 788 |
| 789 // Defined by the WebCrypto spec as: |
| 790 // |
764 // dictionary AesDerivedKeyParams : Algorithm { | 791 // dictionary AesDerivedKeyParams : Algorithm { |
765 // [EnforceRange] required unsigned short length; | 792 // [EnforceRange] required unsigned short length; |
766 // }; | 793 // }; |
767 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) | 794 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
768 { | 795 { |
769 uint16_t length; | 796 uint16_t length; |
770 if (!getUint16(raw, "length", length, context, error)) | 797 if (!getUint16(raw, "length", length, context, error)) |
771 return false; | 798 return false; |
772 | 799 |
773 params = adoptPtr(new WebCryptoAesDerivedKeyParams(length)); | 800 params = adoptPtr(new WebCryptoAesDerivedKeyParams(length)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 return parseEcKeyImportParams(raw, params, context, error); | 878 return parseEcKeyImportParams(raw, params, context, error); |
852 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: | 879 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: |
853 context.add("EcdhKeyDeriveParams"); | 880 context.add("EcdhKeyDeriveParams"); |
854 return parseEcdhKeyDeriveParams(raw, params, context, error); | 881 return parseEcdhKeyDeriveParams(raw, params, context, error); |
855 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: | 882 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: |
856 context.add("AesDerivedKeyParams"); | 883 context.add("AesDerivedKeyParams"); |
857 return parseAesDerivedKeyParams(raw, params, context, error); | 884 return parseAesDerivedKeyParams(raw, params, context, error); |
858 case WebCryptoAlgorithmParamsTypeHkdfParams: | 885 case WebCryptoAlgorithmParamsTypeHkdfParams: |
859 context.add("HkdfParams"); | 886 context.add("HkdfParams"); |
860 return parseHkdfParams(raw, params, context, error); | 887 return parseHkdfParams(raw, params, context, error); |
| 888 case WebCryptoAlgorithmParamsTypePbkdf2Params: |
| 889 context.add("Pbkdf2Params"); |
| 890 return parsePbkdf2Params(raw, params, context, error); |
861 } | 891 } |
862 ASSERT_NOT_REACHED(); | 892 ASSERT_NOT_REACHED(); |
863 return false; | 893 return false; |
864 } | 894 } |
865 | 895 |
866 const char* operationToString(WebCryptoOperation op) | 896 const char* operationToString(WebCryptoOperation op) |
867 { | 897 { |
868 switch (op) { | 898 switch (op) { |
869 case WebCryptoOperationEncrypt: | 899 case WebCryptoOperationEncrypt: |
870 return "encrypt"; | 900 return "encrypt"; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 } | 978 } |
949 | 979 |
950 } // namespace | 980 } // namespace |
951 | 981 |
952 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) | 982 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) |
953 { | 983 { |
954 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 984 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
955 } | 985 } |
956 | 986 |
957 } // namespace blink | 987 } // namespace blink |
OLD | NEW |