Chromium Code Reviews| 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. I am assuming a | |
|
eroman
2015/01/07 00:40:31
Leave out things like "we" and "I" as it is unclea
nharper
2015/01/08 00:58:39
Done.
| |
| 781 // definition along the lines of: | |
| 782 // | |
| 783 // dictionary HkdfParams : Algorithm { | |
| 784 // required HashAlgorithmIdentifier hash; | |
| 785 // required BufferSource salt; | |
| 786 // required BufferSource info; | |
| 787 // }; | |
| 788 bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& pa rams, const ErrorContext& context, AlgorithmError* error) | |
| 789 { | |
| 790 WebCryptoAlgorithm hash; | |
| 791 if (!parseHash(raw, hash, context, error)) | |
| 792 return false; | |
| 793 BufferSource saltBufferSource; | |
| 794 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) | |
| 795 return false; | |
| 796 BufferSource infoBufferSource; | |
| 797 if (!getBufferSource(raw, "info", infoBufferSource, context, error)) | |
| 798 return false; | |
| 799 | |
| 800 DOMArrayPiece salt(saltBufferSource); | |
| 801 DOMArrayPiece info(infoBufferSource); | |
| 802 | |
| 803 params = adoptPtr(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLengt h(), info.bytes(), info.byteLength())); | |
| 804 return true; | |
| 805 } | |
| 806 | |
| 776 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr ror* error) | 807 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr ror* error) |
| 777 { | 808 { |
| 778 switch (type) { | 809 switch (type) { |
| 779 case WebCryptoAlgorithmParamsTypeNone: | 810 case WebCryptoAlgorithmParamsTypeNone: |
| 780 return true; | 811 return true; |
| 781 case WebCryptoAlgorithmParamsTypeAesCbcParams: | 812 case WebCryptoAlgorithmParamsTypeAesCbcParams: |
| 782 context.add("AesCbcParams"); | 813 context.add("AesCbcParams"); |
| 783 return parseAesCbcParams(raw, params, context, error); | 814 return parseAesCbcParams(raw, params, context, error); |
| 784 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 815 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
| 785 context.add("AesKeyGenParams"); | 816 context.add("AesKeyGenParams"); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 816 return parseEcKeyGenParams(raw, params, context, error); | 847 return parseEcKeyGenParams(raw, params, context, error); |
| 817 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: | 848 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: |
| 818 context.add("EcKeyImportParams"); | 849 context.add("EcKeyImportParams"); |
| 819 return parseEcKeyImportParams(raw, params, context, error); | 850 return parseEcKeyImportParams(raw, params, context, error); |
| 820 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: | 851 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: |
| 821 context.add("EcdhKeyDeriveParams"); | 852 context.add("EcdhKeyDeriveParams"); |
| 822 return parseEcdhKeyDeriveParams(raw, params, context, error); | 853 return parseEcdhKeyDeriveParams(raw, params, context, error); |
| 823 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: | 854 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: |
| 824 context.add("AesDerivedKeyParams"); | 855 context.add("AesDerivedKeyParams"); |
| 825 return parseAesDerivedKeyParams(raw, params, context, error); | 856 return parseAesDerivedKeyParams(raw, params, context, error); |
| 857 case WebCryptoAlgorithmParamsTypeHkdfParams: | |
| 858 context.add("HkdfParams"); | |
| 859 return parseHkdfParams(raw, params, context, error); | |
| 826 } | 860 } |
| 827 ASSERT_NOT_REACHED(); | 861 ASSERT_NOT_REACHED(); |
| 828 return false; | 862 return false; |
| 829 } | 863 } |
| 830 | 864 |
| 831 const char* operationToString(WebCryptoOperation op) | 865 const char* operationToString(WebCryptoOperation op) |
| 832 { | 866 { |
| 833 switch (op) { | 867 switch (op) { |
| 834 case WebCryptoOperationEncrypt: | 868 case WebCryptoOperationEncrypt: |
| 835 return "encrypt"; | 869 return "encrypt"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 } | 947 } |
| 914 | 948 |
| 915 } // namespace | 949 } // namespace |
| 916 | 950 |
| 917 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error) | 951 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error) |
| 918 { | 952 { |
| 919 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 953 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
| 920 } | 954 } |
| 921 | 955 |
| 922 } // namespace blink | 956 } // namespace blink |
| OLD | NEW |