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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const AlgorithmNameMapping algorithmNameMappings[] = { | 65 const AlgorithmNameMapping algorithmNameMappings[] = { |
66 {"HMAC", 4, blink::WebCryptoAlgorithmIdHmac}, | 66 {"HMAC", 4, blink::WebCryptoAlgorithmIdHmac}, |
67 {"SHA-1", 5, blink::WebCryptoAlgorithmIdSha1}, | 67 {"SHA-1", 5, blink::WebCryptoAlgorithmIdSha1}, |
68 {"AES-KW", 6, blink::WebCryptoAlgorithmIdAesKw}, | 68 {"AES-KW", 6, blink::WebCryptoAlgorithmIdAesKw}, |
69 {"SHA-512", 7, blink::WebCryptoAlgorithmIdSha512}, | 69 {"SHA-512", 7, blink::WebCryptoAlgorithmIdSha512}, |
70 {"SHA-384", 7, blink::WebCryptoAlgorithmIdSha384}, | 70 {"SHA-384", 7, blink::WebCryptoAlgorithmIdSha384}, |
71 {"SHA-256", 7, blink::WebCryptoAlgorithmIdSha256}, | 71 {"SHA-256", 7, blink::WebCryptoAlgorithmIdSha256}, |
72 {"AES-CBC", 7, blink::WebCryptoAlgorithmIdAesCbc}, | 72 {"AES-CBC", 7, blink::WebCryptoAlgorithmIdAesCbc}, |
73 {"AES-GCM", 7, blink::WebCryptoAlgorithmIdAesGcm}, | 73 {"AES-GCM", 7, blink::WebCryptoAlgorithmIdAesGcm}, |
74 {"AES-CTR", 7, blink::WebCryptoAlgorithmIdAesCtr}, | 74 {"AES-CTR", 7, blink::WebCryptoAlgorithmIdAesCtr}, |
| 75 {"RSA-OAEP", 8, blink::WebCryptoAlgorithmIdRsaOaep}, |
75 {"RSAES-PKCS1-V1_5", 16, blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, | 76 {"RSAES-PKCS1-V1_5", 16, blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, |
76 {"RSASSA-PKCS1-V1_5", 17, blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, | 77 {"RSASSA-PKCS1-V1_5", 17, blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, |
77 }; | 78 }; |
78 | 79 |
79 typedef char ParamsTypeOrUndefined; | 80 typedef char ParamsTypeOrUndefined; |
80 const ParamsTypeOrUndefined Undefined = -1; | 81 const ParamsTypeOrUndefined Undefined = -1; |
81 | 82 |
82 struct AlgorithmInfo { | 83 struct AlgorithmInfo { |
83 // The canonical (case-sensitive) name for the algorithm. | 84 // The canonical (case-sensitive) name for the algorithm. |
84 const char* name; | 85 const char* name; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 Undefined, // Digest | 212 Undefined, // Digest |
212 blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey | 213 blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey |
213 blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey | 214 blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey |
214 Undefined, // DeriveKey | 215 Undefined, // DeriveKey |
215 Undefined, // DeriveBits | 216 Undefined, // DeriveBits |
216 blink::WebCryptoAlgorithmParamsTypeAesGcmParams, // WrapKey | 217 blink::WebCryptoAlgorithmParamsTypeAesGcmParams, // WrapKey |
217 blink::WebCryptoAlgorithmParamsTypeAesGcmParams // UnwrapKey | 218 blink::WebCryptoAlgorithmParamsTypeAesGcmParams // UnwrapKey |
218 } | 219 } |
219 }, { // Index 9 | 220 }, { // Index 9 |
220 "RSA-OAEP", { | 221 "RSA-OAEP", { |
221 // FIXME: | 222 blink::WebCryptoAlgorithmParamsTypeRsaOaepParams, // Encrypt |
222 Undefined, // Encrypt | 223 blink::WebCryptoAlgorithmParamsTypeRsaOaepParams, // Decrypt |
223 Undefined, // Decrypt | |
224 Undefined, // Sign | 224 Undefined, // Sign |
225 Undefined, // Verify | 225 Undefined, // Verify |
226 Undefined, // Digest | 226 Undefined, // Digest |
227 Undefined, // GenerateKey | 227 blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // Generat
eKey |
228 Undefined, // ImportKey | 228 blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportK
ey |
229 Undefined, // DeriveKey | 229 Undefined, // DeriveKey |
230 Undefined, // DeriveBits | 230 Undefined, // DeriveBits |
231 Undefined, // WrapKey | 231 blink::WebCryptoAlgorithmParamsTypeRsaOaepParams, // WrapKey |
232 Undefined // UnwrapKey | 232 blink::WebCryptoAlgorithmParamsTypeRsaOaepParams // UnwrapKey |
233 } | 233 } |
234 }, { // Index 10 | 234 }, { // Index 10 |
235 "AES-CTR", { | 235 "AES-CTR", { |
236 blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // Encrypt | 236 blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // Encrypt |
237 blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // Decrypt | 237 blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // Decrypt |
238 Undefined, // Sign | 238 Undefined, // Sign |
239 Undefined, // Verify | 239 Undefined, // Verify |
240 Undefined, // Digest | 240 Undefined, // Digest |
241 blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey | 241 blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey |
242 blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey | 242 blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 const unsigned char* ivStart = static_cast<const unsigned char*>(iv->baseAdd
ress()); | 811 const unsigned char* ivStart = static_cast<const unsigned char*>(iv->baseAdd
ress()); |
812 unsigned ivLength = iv->byteLength(); | 812 unsigned ivLength = iv->byteLength(); |
813 | 813 |
814 const unsigned char* additionalDataStart = hasAdditionalData ? static_cast<c
onst unsigned char*>(additionalData->baseAddress()) : 0; | 814 const unsigned char* additionalDataStart = hasAdditionalData ? static_cast<c
onst unsigned char*>(additionalData->baseAddress()) : 0; |
815 unsigned additionalDataLength = hasAdditionalData ? additionalData->byteLeng
th() : 0; | 815 unsigned additionalDataLength = hasAdditionalData ? additionalData->byteLeng
th() : 0; |
816 | 816 |
817 params = adoptPtr(new blink::WebCryptoAesGcmParams(ivStart, ivLength, hasAdd
itionalData, additionalDataStart, additionalDataLength, hasTagLength, tagLength)
); | 817 params = adoptPtr(new blink::WebCryptoAesGcmParams(ivStart, ivLength, hasAdd
itionalData, additionalDataStart, additionalDataLength, hasTagLength, tagLength)
); |
818 return true; | 818 return true; |
819 } | 819 } |
820 | 820 |
| 821 // Defined by the WebCrypto spec as: |
| 822 // |
| 823 // dictionary RsaOaepParams : Algorithm { |
| 824 // CryptoOperationData? label; |
| 825 // }; |
| 826 bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, CryptoResult* result) |
| 827 { |
| 828 bool hasLabel; |
| 829 RefPtr<ArrayBufferView> label; |
| 830 if (!getOptionalCryptoOperationData(raw, "label", hasLabel, label, context,
result)) |
| 831 return false; |
| 832 |
| 833 const unsigned char* labelStart = hasLabel ? static_cast<const unsigned char
*>(label->baseAddress()) : 0; |
| 834 unsigned labelLength = hasLabel ? label->byteLength() : 0; |
| 835 |
| 836 params = adoptPtr(new blink::WebCryptoRsaOaepParams(hasLabel, labelStart, la
belLength)); |
| 837 return true; |
| 838 } |
| 839 |
821 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, CryptoResult* result) | 840 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, CryptoResult* result) |
822 { | 841 { |
823 switch (type) { | 842 switch (type) { |
824 case blink::WebCryptoAlgorithmParamsTypeNone: | 843 case blink::WebCryptoAlgorithmParamsTypeNone: |
825 return true; | 844 return true; |
826 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: | 845 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: |
827 context.add("AesCbcParams"); | 846 context.add("AesCbcParams"); |
828 return parseAesCbcParams(raw, params, context, result); | 847 return parseAesCbcParams(raw, params, context, result); |
829 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 848 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
830 context.add("AesKeyGenParams"); | 849 context.add("AesKeyGenParams"); |
(...skipping 13 matching lines...) Expand all Loading... |
844 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 863 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
845 context.add("RsaKeyGenParams"); | 864 context.add("RsaKeyGenParams"); |
846 return parseRsaKeyGenParams(raw, params, context, result); | 865 return parseRsaKeyGenParams(raw, params, context, result); |
847 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: | 866 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: |
848 context.add("AesCtrParams"); | 867 context.add("AesCtrParams"); |
849 return parseAesCtrParams(raw, params, context, result); | 868 return parseAesCtrParams(raw, params, context, result); |
850 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: | 869 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
851 context.add("AesGcmParams"); | 870 context.add("AesGcmParams"); |
852 return parseAesGcmParams(raw, params, context, result); | 871 return parseAesGcmParams(raw, params, context, result); |
853 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 872 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
854 // TODO | 873 context.add("RsaOaepParams"); |
855 notImplemented(); | 874 return parseRsaOaepParams(raw, params, context, result); |
856 break; | 875 break; |
857 } | 876 } |
858 ASSERT_NOT_REACHED(); | 877 ASSERT_NOT_REACHED(); |
859 return false; | 878 return false; |
860 } | 879 } |
861 | 880 |
862 const char* operationToString(AlgorithmOperation op) | 881 const char* operationToString(AlgorithmOperation op) |
863 { | 882 { |
864 switch (op) { | 883 switch (op) { |
865 case Encrypt: | 884 case Encrypt: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 { | 957 { |
939 return parseAlgorithm(raw, op, algorithm, ErrorContext(), result); | 958 return parseAlgorithm(raw, op, algorithm, ErrorContext(), result); |
940 } | 959 } |
941 | 960 |
942 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) | 961 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
943 { | 962 { |
944 return lookupAlgorithmInfo(id)->name; | 963 return lookupAlgorithmInfo(id)->name; |
945 } | 964 } |
946 | 965 |
947 } // namespace WebCore | 966 } // namespace WebCore |
OLD | NEW |