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 // The WebCrypto spec hasn't been updated yet to define HKDF. I am assuming a | |
eroman
2014/12/23 20:58:24
Please add a FIXME or a link to a bug, so that the
nharper
2014/12/23 22:46:59
Done.
| |
778 // definition along the lines of: | |
779 // | |
780 // dictionary HkdfParams : Algorithm { | |
eroman
2014/12/23 20:58:24
How confident are you that this API will match the
nharper
2014/12/23 22:46:59
I'm not confident that this will match the spec. T
eroman
2014/12/23 23:34:29
Changing a required parameter from required -> opt
| |
781 // required HashAlgorithmIdentifier hash; | |
782 // required BufferSource salt; | |
783 // required BufferSource info; | |
784 // }; | |
785 // | |
786 // It is possible that salt will be changed to be optional. | |
eroman
2014/12/23 20:58:24
nit: no need for this comment, already covered by
nharper
2014/12/23 22:46:59
Done.
| |
787 bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& pa rams, const ErrorContext& context, AlgorithmError* error) | |
788 { | |
789 WebCryptoAlgorithm hash; | |
790 if (!parseHash(raw, hash, context, error)) | |
791 return false; | |
792 BufferSource saltBufferSource; | |
793 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) | |
794 return false; | |
795 BufferSource infoBufferSource; | |
796 if (!getBufferSource(raw, "info", infoBufferSource, context, error)) | |
797 return false; | |
798 | |
799 DOMArrayPiece salt(saltBufferSource); | |
800 DOMArrayPiece info(infoBufferSource); | |
801 | |
802 params = adoptPtr(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLengt h(), info.bytes(), info.byteLength())); | |
803 return true; | |
804 } | |
805 | |
776 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr ror* error) | 806 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr ror* error) |
777 { | 807 { |
778 switch (type) { | 808 switch (type) { |
779 case WebCryptoAlgorithmParamsTypeNone: | 809 case WebCryptoAlgorithmParamsTypeNone: |
780 return true; | 810 return true; |
781 case WebCryptoAlgorithmParamsTypeAesCbcParams: | 811 case WebCryptoAlgorithmParamsTypeAesCbcParams: |
782 context.add("AesCbcParams"); | 812 context.add("AesCbcParams"); |
783 return parseAesCbcParams(raw, params, context, error); | 813 return parseAesCbcParams(raw, params, context, error); |
784 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 814 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
785 context.add("AesKeyGenParams"); | 815 context.add("AesKeyGenParams"); |
(...skipping 30 matching lines...) Expand all Loading... | |
816 return parseEcKeyGenParams(raw, params, context, error); | 846 return parseEcKeyGenParams(raw, params, context, error); |
817 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: | 847 case WebCryptoAlgorithmParamsTypeEcKeyImportParams: |
818 context.add("EcKeyImportParams"); | 848 context.add("EcKeyImportParams"); |
819 return parseEcKeyImportParams(raw, params, context, error); | 849 return parseEcKeyImportParams(raw, params, context, error); |
820 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: | 850 case WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams: |
821 context.add("EcdhKeyDeriveParams"); | 851 context.add("EcdhKeyDeriveParams"); |
822 return parseEcdhKeyDeriveParams(raw, params, context, error); | 852 return parseEcdhKeyDeriveParams(raw, params, context, error); |
823 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: | 853 case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams: |
824 context.add("AesDerivedKeyParams"); | 854 context.add("AesDerivedKeyParams"); |
825 return parseAesDerivedKeyParams(raw, params, context, error); | 855 return parseAesDerivedKeyParams(raw, params, context, error); |
856 case WebCryptoAlgorithmParamsTypeHkdfParams: | |
857 context.add("HkdfParams"); | |
858 return parseHkdfParams(raw, params, context, error); | |
826 } | 859 } |
827 ASSERT_NOT_REACHED(); | 860 ASSERT_NOT_REACHED(); |
828 return false; | 861 return false; |
829 } | 862 } |
830 | 863 |
831 const char* operationToString(WebCryptoOperation op) | 864 const char* operationToString(WebCryptoOperation op) |
832 { | 865 { |
833 switch (op) { | 866 switch (op) { |
834 case WebCryptoOperationEncrypt: | 867 case WebCryptoOperationEncrypt: |
835 return "encrypt"; | 868 return "encrypt"; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 } | 946 } |
914 | 947 |
915 } // namespace | 948 } // namespace |
916 | 949 |
917 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error) | 950 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error) |
918 { | 951 { |
919 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 952 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
920 } | 953 } |
921 | 954 |
922 } // namespace blink | 955 } // namespace blink |
OLD | NEW |