| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 #if ENABLE(ASSERT) | 61 #if ENABLE(ASSERT) |
| 62 bool operator<(const AlgorithmNameMapping&) const; | 62 bool operator<(const AlgorithmNameMapping&) const; |
| 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 {"HKDF", 4, WebCryptoAlgorithmIdHkdf}, |
| 70 {"ECDH", 4, WebCryptoAlgorithmIdEcdh}, | 71 {"ECDH", 4, WebCryptoAlgorithmIdEcdh}, |
| 71 {"SHA-1", 5, WebCryptoAlgorithmIdSha1}, | 72 {"SHA-1", 5, WebCryptoAlgorithmIdSha1}, |
| 72 {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa}, | 73 {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa}, |
| 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}, |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) | 767 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
| 767 { | 768 { |
| 768 uint16_t length; | 769 uint16_t length; |
| 769 if (!getUint16(raw, "length", length, context, error)) | 770 if (!getUint16(raw, "length", length, context, error)) |
| 770 return false; | 771 return false; |
| 771 | 772 |
| 772 params = adoptPtr(new WebCryptoAesDerivedKeyParams(length)); | 773 params = adoptPtr(new WebCryptoAesDerivedKeyParams(length)); |
| 773 return true; | 774 return true; |
| 774 } | 775 } |
| 775 | 776 |
| 777 // FIXME: once the spec has been updated, check that the implementation is |
| 778 // still correct and update this comment. http://crbug.com/399095 |
| 779 // |
| 780 // The WebCrypto spec hasn't been updated yet to define HKDF |
| 781 // (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27425). The assumed |
| 782 // parameters are: |
| 783 // |
| 784 // dictionary HkdfParams : Algorithm { |
| 785 // required HashAlgorithmIdentifier hash; |
| 786 // required BufferSource salt; |
| 787 // required BufferSource info; |
| 788 // }; |
| 789 bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& pa
rams, const ErrorContext& context, AlgorithmError* error) |
| 790 { |
| 791 WebCryptoAlgorithm hash; |
| 792 if (!parseHash(raw, hash, context, error)) |
| 793 return false; |
| 794 BufferSource saltBufferSource; |
| 795 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) |
| 796 return false; |
| 797 BufferSource infoBufferSource; |
| 798 if (!getBufferSource(raw, "info", infoBufferSource, context, error)) |
| 799 return false; |
| 800 |
| 801 DOMArrayPiece salt(saltBufferSource); |
| 802 DOMArrayPiece info(infoBufferSource); |
| 803 |
| 804 params = adoptPtr(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLengt
h(), info.bytes(), info.byteLength())); |
| 805 return true; |
| 806 } |
| 807 |
| 776 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr
ror* error) | 808 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr
ror* error) |
| 777 { | 809 { |
| 778 switch (type) { | 810 switch (type) { |
| 779 case WebCryptoAlgorithmParamsTypeNone: | 811 case WebCryptoAlgorithmParamsTypeNone: |
| 780 return true; | 812 return true; |
| 781 case WebCryptoAlgorithmParamsTypeAesCbcParams: | 813 case WebCryptoAlgorithmParamsTypeAesCbcParams: |
| 782 context.add("AesCbcParams"); | 814 context.add("AesCbcParams"); |
| 783 return parseAesCbcParams(raw, params, context, error); | 815 return parseAesCbcParams(raw, params, context, error); |
| 784 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 816 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
| 785 context.add("AesKeyGenParams"); | 817 context.add("AesKeyGenParams"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 816 return parseEcKeyGenParams(raw, params, context, error); | 848 return parseEcKeyGenParams(raw, params, context, error); |
| 817 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: | 849 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: |
| 818 context.add("EcKeyImportParams"); | 850 context.add("EcKeyImportParams"); |
| 819 return parseEcKeyImportParams(raw, params, context, error); | 851 return parseEcKeyImportParams(raw, params, context, error); |
| 820 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: | 852 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: |
| 821 context.add("EcdhKeyDeriveParams"); | 853 context.add("EcdhKeyDeriveParams"); |
| 822 return parseEcdhKeyDeriveParams(raw, params, context, error); | 854 return parseEcdhKeyDeriveParams(raw, params, context, error); |
| 823 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: | 855 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: |
| 824 context.add("AesDerivedKeyParams"); | 856 context.add("AesDerivedKeyParams"); |
| 825 return parseAesDerivedKeyParams(raw, params, context, error); | 857 return parseAesDerivedKeyParams(raw, params, context, error); |
| 858 case WebCryptoAlgorithmParamsTypeHkdfParams: |
| 859 context.add("HkdfParams"); |
| 860 return parseHkdfParams(raw, params, context, error); |
| 826 } | 861 } |
| 827 ASSERT_NOT_REACHED(); | 862 ASSERT_NOT_REACHED(); |
| 828 return false; | 863 return false; |
| 829 } | 864 } |
| 830 | 865 |
| 831 const char* operationToString(WebCryptoOperation op) | 866 const char* operationToString(WebCryptoOperation op) |
| 832 { | 867 { |
| 833 switch (op) { | 868 switch (op) { |
| 834 case WebCryptoOperationEncrypt: | 869 case WebCryptoOperationEncrypt: |
| 835 return "encrypt"; | 870 return "encrypt"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 } | 948 } |
| 914 | 949 |
| 915 } // namespace | 950 } // namespace |
| 916 | 951 |
| 917 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) | 952 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) |
| 918 { | 953 { |
| 919 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 954 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
| 920 } | 955 } |
| 921 | 956 |
| 922 } // namespace blink | 957 } // namespace blink |
| OLD | NEW |