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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 struct OperationParamsMapping { | 63 struct OperationParamsMapping { |
64 blink::WebCryptoAlgorithmId algorithmId; | 64 blink::WebCryptoAlgorithmId algorithmId; |
65 AlgorithmOperation operation; | 65 AlgorithmOperation operation; |
66 AlgorithmParamsForOperation params; | 66 AlgorithmParamsForOperation params; |
67 }; | 67 }; |
68 | 68 |
69 const AlgorithmNameMapping algorithmNameMappings[] = { | 69 const AlgorithmNameMapping algorithmNameMappings[] = { |
70 {"AES-CBC", blink::WebCryptoAlgorithmIdAesCbc}, | 70 {"AES-CBC", blink::WebCryptoAlgorithmIdAesCbc}, |
71 {"AES-CTR", blink::WebCryptoAlgorithmIdAesCtr}, | 71 {"AES-CTR", blink::WebCryptoAlgorithmIdAesCtr}, |
| 72 {"AES-GCM", blink::WebCryptoAlgorithmIdAesGcm}, |
72 {"HMAC", blink::WebCryptoAlgorithmIdHmac}, | 73 {"HMAC", blink::WebCryptoAlgorithmIdHmac}, |
73 {"RSASSA-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, | 74 {"RSASSA-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, |
74 {"RSAES-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, | 75 {"RSAES-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, |
75 {"SHA-1", blink::WebCryptoAlgorithmIdSha1}, | 76 {"SHA-1", blink::WebCryptoAlgorithmIdSha1}, |
76 {"SHA-224", blink::WebCryptoAlgorithmIdSha224}, | 77 {"SHA-224", blink::WebCryptoAlgorithmIdSha224}, |
77 {"SHA-256", blink::WebCryptoAlgorithmIdSha256}, | 78 {"SHA-256", blink::WebCryptoAlgorithmIdSha256}, |
78 {"SHA-384", blink::WebCryptoAlgorithmIdSha384}, | 79 {"SHA-384", blink::WebCryptoAlgorithmIdSha384}, |
79 {"SHA-512", blink::WebCryptoAlgorithmIdSha512}, | 80 {"SHA-512", blink::WebCryptoAlgorithmIdSha512}, |
80 {"AES-KW", blink::WebCryptoAlgorithmIdAesKw}, | 81 {"AES-KW", blink::WebCryptoAlgorithmIdAesKw}, |
81 }; | 82 }; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 {blink::WebCryptoAlgorithmIdSha224, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, | 124 {blink::WebCryptoAlgorithmIdSha224, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
124 {blink::WebCryptoAlgorithmIdSha256, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, | 125 {blink::WebCryptoAlgorithmIdSha256, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
125 {blink::WebCryptoAlgorithmIdSha384, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, | 126 {blink::WebCryptoAlgorithmIdSha384, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
126 {blink::WebCryptoAlgorithmIdSha512, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, | 127 {blink::WebCryptoAlgorithmIdSha512, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
127 | 128 |
128 // AES-KW | 129 // AES-KW |
129 {blink::WebCryptoAlgorithmIdAesKw, GenerateKey, blink::WebCryptoAlgorithmPar
amsTypeAesKeyGenParams}, | 130 {blink::WebCryptoAlgorithmIdAesKw, GenerateKey, blink::WebCryptoAlgorithmPar
amsTypeAesKeyGenParams}, |
130 {blink::WebCryptoAlgorithmIdAesKw, ImportKey, blink::WebCryptoAlgorithmParam
sTypeNone}, | 131 {blink::WebCryptoAlgorithmIdAesKw, ImportKey, blink::WebCryptoAlgorithmParam
sTypeNone}, |
131 {blink::WebCryptoAlgorithmIdAesKw, UnwrapKey, blink::WebCryptoAlgorithmParam
sTypeNone}, | 132 {blink::WebCryptoAlgorithmIdAesKw, UnwrapKey, blink::WebCryptoAlgorithmParam
sTypeNone}, |
132 {blink::WebCryptoAlgorithmIdAesKw, WrapKey, blink::WebCryptoAlgorithmParamsT
ypeNone}, | 133 {blink::WebCryptoAlgorithmIdAesKw, WrapKey, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
| 134 |
| 135 // AES-GCM |
| 136 {blink::WebCryptoAlgorithmIdAesGcm, GenerateKey, blink::WebCryptoAlgorithmPa
ramsTypeAesKeyGenParams}, |
| 137 {blink::WebCryptoAlgorithmIdAesGcm, ImportKey, blink::WebCryptoAlgorithmPara
msTypeNone}, |
| 138 {blink::WebCryptoAlgorithmIdAesGcm, Encrypt, blink::WebCryptoAlgorithmParams
TypeAesGcmParams}, |
| 139 {blink::WebCryptoAlgorithmIdAesGcm, Decrypt, blink::WebCryptoAlgorithmParams
TypeAesGcmParams}, |
| 140 {blink::WebCryptoAlgorithmIdAesGcm, UnwrapKey, blink::WebCryptoAlgorithmPara
msTypeAesGcmParams}, |
| 141 {blink::WebCryptoAlgorithmIdAesGcm, WrapKey, blink::WebCryptoAlgorithmParams
TypeAesGcmParams}, |
133 }; | 142 }; |
134 | 143 |
135 // This structure describes an algorithm and its supported operations. | 144 // This structure describes an algorithm and its supported operations. |
136 struct AlgorithmInfo { | 145 struct AlgorithmInfo { |
137 AlgorithmInfo() | 146 AlgorithmInfo() |
138 : algorithmName(0) | 147 : algorithmName(0) |
139 { | 148 { |
140 for (size_t i = 0; i < WTF_ARRAY_LENGTH(paramsForOperation); ++i) | 149 for (size_t i = 0; i < WTF_ARRAY_LENGTH(paramsForOperation); ++i) |
141 paramsForOperation[i] = UnsupportedOp; | 150 paramsForOperation[i] = UnsupportedOp; |
142 } | 151 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 stack.add(message2); | 259 stack.add(message2); |
251 return stack.toString(); | 260 return stack.toString(); |
252 } | 261 } |
253 | 262 |
254 private: | 263 private: |
255 // This inline size is large enough to avoid having to grow the Vector in | 264 // This inline size is large enough to avoid having to grow the Vector in |
256 // the majority of cases (up to 1 nested algorithm identifier). | 265 // the majority of cases (up to 1 nested algorithm identifier). |
257 Vector<const char*, 10> m_messages; | 266 Vector<const char*, 10> m_messages; |
258 }; | 267 }; |
259 | 268 |
260 bool getArrayBufferView(const Dictionary& raw, const char* propertyName, RefPtr<
ArrayBufferView>& buffer, const ErrorContext& context, String& errorDetails) | 269 // Defined by the WebCrypto spec as: |
| 270 // |
| 271 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; |
| 272 // |
| 273 // FIXME: Currently only supports ArrayBufferView. |
| 274 bool getOptionalCryptoOperationData(const Dictionary& raw, const char* propertyN
ame, bool& hasProperty, RefPtr<ArrayBufferView>& buffer, const ErrorContext& con
text, String& errorDetails) |
261 { | 275 { |
262 if (!raw.get(propertyName, buffer) || !buffer) { | 276 if (!raw.get(propertyName, buffer)) { |
263 errorDetails = context.toString(propertyName, "Missing or not a ArrayBuf
ferView"); | 277 hasProperty = false; |
| 278 return true; |
| 279 } |
| 280 |
| 281 hasProperty = true; |
| 282 |
| 283 if (!buffer) { |
| 284 errorDetails = context.toString(propertyName, "Not an ArrayBufferView"); |
264 return false; | 285 return false; |
265 } | 286 } |
| 287 |
266 return true; | 288 return true; |
267 } | 289 } |
268 | 290 |
| 291 // Defined by the WebCrypto spec as: |
| 292 // |
| 293 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; |
| 294 // |
| 295 // FIXME: Currently only supports ArrayBufferView. |
| 296 bool getCryptoOperationData(const Dictionary& raw, const char* propertyName, Ref
Ptr<ArrayBufferView>& buffer, const ErrorContext& context, String& errorDetails) |
| 297 { |
| 298 bool hasProperty; |
| 299 bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buf
fer, context, errorDetails); |
| 300 if (!hasProperty) { |
| 301 errorDetails = context.toString(propertyName, "Missing required property
"); |
| 302 return false; |
| 303 } |
| 304 return ok; |
| 305 } |
| 306 |
269 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, String& errorDetails) | 307 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, String& errorDetails) |
270 { | 308 { |
271 if (!raw.get(propertyName, array) || !array) { | 309 if (!raw.get(propertyName, array) || !array) { |
272 errorDetails = context.toString(propertyName, "Missing or not a Uint8Arr
ay"); | 310 errorDetails = context.toString(propertyName, "Missing or not a Uint8Arr
ay"); |
273 return false; | 311 return false; |
274 } | 312 } |
275 return true; | 313 return true; |
276 } | 314 } |
277 | 315 |
| 316 // Defined by the WebCrypto spec as: |
| 317 // |
| 318 // typedef Uint8Array BigInteger; |
| 319 bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, String& errorDetails) |
| 320 { |
| 321 if (!getUint8Array(raw, propertyName, array, context, errorDetails)) |
| 322 return false; |
| 323 |
| 324 if (!array->byteLength()) { |
| 325 errorDetails = context.toString(propertyName, "BigInteger should not be
empty"); |
| 326 return false; |
| 327 } |
| 328 |
| 329 if (!raw.get(propertyName, array) || !array) { |
| 330 errorDetails = context.toString(propertyName, "Missing or not a Uint8Arr
ay"); |
| 331 return false; |
| 332 } |
| 333 return true; |
| 334 } |
| 335 |
278 // Gets an integer according to WebIDL's [EnforceRange]. | 336 // Gets an integer according to WebIDL's [EnforceRange]. |
279 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, String& errorDetails) | 337 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, String& errorDetails) |
280 { | 338 { |
281 double number; | 339 double number; |
282 bool ok = raw.get(propertyName, number, hasProperty); | 340 bool ok = raw.get(propertyName, number, hasProperty); |
283 | 341 |
284 if (!hasProperty) | 342 if (!hasProperty) |
285 return true; | 343 return true; |
286 | 344 |
287 if (!ok || std::isnan(number)) { | 345 if (!ok || std::isnan(number)) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ErrorContext& context, String& errorDetails) | 402 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ErrorContext& context, String& errorDetails) |
345 { | 403 { |
346 double number; | 404 double number; |
347 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, errorDetails)) | 405 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, errorDetails)) |
348 return false; | 406 return false; |
349 if (hasValue) | 407 if (hasValue) |
350 value = number; | 408 value = number; |
351 return true; | 409 return true; |
352 } | 410 } |
353 | 411 |
| 412 // Defined by the WebCrypto spec as: |
| 413 // |
| 414 // dictionary AesCbcParams : Algorithm { |
| 415 // CryptoOperationData iv; |
| 416 // }; |
354 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) | 417 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) |
355 { | 418 { |
356 RefPtr<ArrayBufferView> iv; | 419 RefPtr<ArrayBufferView> iv; |
357 if (!getArrayBufferView(raw, "iv", iv, context, errorDetails)) | 420 if (!getCryptoOperationData(raw, "iv", iv, context, errorDetails)) |
358 return false; | 421 return false; |
359 | 422 |
360 if (iv->byteLength() != 16) { | 423 if (iv->byteLength() != 16) { |
361 errorDetails = context.toString("iv", "Must be 16 bytes"); | 424 errorDetails = context.toString("iv", "Must be 16 bytes"); |
362 return false; | 425 return false; |
363 } | 426 } |
364 | 427 |
365 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char
*>(iv->baseAddress()), iv->byteLength())); | 428 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char
*>(iv->baseAddress()), iv->byteLength())); |
366 return true; | 429 return true; |
367 } | 430 } |
368 | 431 |
| 432 // Defined by the WebCrypto spec as: |
| 433 // |
| 434 // dictionary AesKeyGenParams : Algorithm { |
| 435 // [EnforceRange] unsigned short length; |
| 436 // }; |
369 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) | 437 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) |
370 { | 438 { |
371 uint16_t length; | 439 uint16_t length; |
372 if (!getUint16(raw, "length", length, context, errorDetails)) | 440 if (!getUint16(raw, "length", length, context, errorDetails)) |
373 return false; | 441 return false; |
374 | 442 |
375 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); | 443 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); |
376 return true; | 444 return true; |
377 } | 445 } |
378 | 446 |
379 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor
ithm&, ErrorContext, String&); | 447 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor
ithm&, ErrorContext, String&); |
380 | 448 |
381 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
ext context, String& errorDetails) | 449 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
ext context, String& errorDetails) |
382 { | 450 { |
383 Dictionary rawHash; | 451 Dictionary rawHash; |
384 if (!raw.get("hash", rawHash)) { | 452 if (!raw.get("hash", rawHash)) { |
385 errorDetails = context.toString("hash", "Missing or not a dictionary"); | 453 errorDetails = context.toString("hash", "Missing or not a dictionary"); |
386 return false; | 454 return false; |
387 } | 455 } |
388 | 456 |
389 context.add("hash"); | 457 context.add("hash"); |
390 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); | 458 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); |
391 } | 459 } |
392 | 460 |
| 461 // Defined by the WebCrypto spec as: |
| 462 // |
| 463 // dictionary HmacImportParams : Algorithm { |
| 464 // AlgorithmIdentifier hash; |
| 465 // }; |
393 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ErrorContext& context, String& errorDetails) | 466 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ErrorContext& context, String& errorDetails) |
394 { | 467 { |
395 blink::WebCryptoAlgorithm hash; | 468 blink::WebCryptoAlgorithm hash; |
396 if (!parseHash(raw, hash, context, errorDetails)) | 469 if (!parseHash(raw, hash, context, errorDetails)) |
397 return false; | 470 return false; |
398 | 471 |
399 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); | 472 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); |
400 return true; | 473 return true; |
401 } | 474 } |
402 | 475 |
| 476 // Defined by the WebCrypto spec as: |
| 477 // |
| 478 // dictionary HmacKeyGenParams : Algorithm { |
| 479 // AlgorithmIdentifier hash; |
| 480 // // The length (in bytes) of the key to generate. If unspecified, the |
| 481 // // recommended length will be used, which is the size of the associated
hash function's block |
| 482 // // size. |
| 483 // unsigned long length; |
| 484 // }; |
403 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, String& errorDetails) | 485 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, String& errorDetails) |
404 { | 486 { |
405 blink::WebCryptoAlgorithm hash; | 487 blink::WebCryptoAlgorithm hash; |
406 if (!parseHash(raw, hash, context, errorDetails)) | 488 if (!parseHash(raw, hash, context, errorDetails)) |
407 return false; | 489 return false; |
408 | 490 |
409 bool hasLength; | 491 bool hasLength; |
410 uint32_t length = 0; | 492 uint32_t length = 0; |
411 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai
ls)) | 493 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai
ls)) |
412 return false; | 494 return false; |
413 | 495 |
414 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length)
); | 496 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length)
); |
415 return true; | 497 return true; |
416 } | 498 } |
417 | 499 |
418 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) | 500 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) |
419 { | 501 { |
420 blink::WebCryptoAlgorithm hash; | 502 blink::WebCryptoAlgorithm hash; |
421 if (!parseHash(raw, hash, context, errorDetails)) | 503 if (!parseHash(raw, hash, context, errorDetails)) |
422 return false; | 504 return false; |
423 | 505 |
424 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash)); | 506 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash)); |
425 return true; | 507 return true; |
426 } | 508 } |
427 | 509 |
| 510 // Defined by the WebCrypto spec as: |
| 511 // |
| 512 // dictionary RsaKeyGenParams : Algorithm { |
| 513 // unsigned long modulusLength; |
| 514 // BigInteger publicExponent; |
| 515 // }; |
428 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) | 516 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) |
429 { | 517 { |
430 uint32_t modulusLength; | 518 uint32_t modulusLength; |
431 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) | 519 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) |
432 return false; | 520 return false; |
433 | 521 |
434 RefPtr<Uint8Array> publicExponent; | 522 RefPtr<Uint8Array> publicExponent; |
435 if (!getUint8Array(raw, "publicExponent", publicExponent, context, errorDeta
ils)) | 523 if (!getBigInteger(raw, "publicExponent", publicExponent, context, errorDeta
ils)) |
436 return false; | 524 return false; |
437 | 525 |
438 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); | 526 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); |
439 return true; | 527 return true; |
440 } | 528 } |
441 | 529 |
442 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& es) | 530 // Defined by the WebCrypto spec as: |
| 531 // |
| 532 // dictionary AesCtrParams : Algorithm { |
| 533 // CryptoOperationData counter; |
| 534 // [EnforceRange] octet length; |
| 535 // }; |
| 536 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) |
443 { | 537 { |
444 RefPtr<Uint8Array> counter; | 538 RefPtr<ArrayBufferView> counter; |
445 if (!getUint8Array(raw, "counter", counter, context, es)) | 539 if (!getCryptoOperationData(raw, "counter", counter, context, errorDetails)) |
446 return false; | 540 return false; |
447 | 541 |
448 uint8_t length; | 542 uint8_t length; |
449 if (!getUint8(raw, "length", length, context, es)) | 543 if (!getUint8(raw, "length", length, context, errorDetails)) |
450 return false; | 544 return false; |
451 | 545 |
452 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const
unsigned char*>(counter->baseAddress()), counter->byteLength())); | 546 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const
unsigned char*>(counter->baseAddress()), counter->byteLength())); |
453 return true; | 547 return true; |
454 } | 548 } |
455 | 549 |
| 550 // Defined by the WebCrypto spec as: |
| 551 // |
| 552 // dictionary AesGcmParams : Algorithm { |
| 553 // CryptoOperationData iv; |
| 554 // CryptoOperationData? additionalData; |
| 555 // [EnforceRange] octet? tagLength; // May be 0-128 |
| 556 // } |
| 557 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) |
| 558 { |
| 559 RefPtr<ArrayBufferView> iv; |
| 560 if (!getCryptoOperationData(raw, "iv", iv, context, errorDetails)) |
| 561 return false; |
| 562 |
| 563 bool hasAdditionalData; |
| 564 RefPtr<ArrayBufferView> additionalData; |
| 565 if (!getOptionalCryptoOperationData(raw, "additionalData", hasAdditionalData
, additionalData, context, errorDetails)) |
| 566 return false; |
| 567 |
| 568 double tagLength; |
| 569 bool hasTagLength; |
| 570 if (!getOptionalInteger(raw, "tagLength", hasTagLength, tagLength, 0, 128, c
ontext, errorDetails)) |
| 571 return false; |
| 572 |
| 573 const unsigned char* ivStart = static_cast<const unsigned char*>(iv->baseAdd
ress()); |
| 574 unsigned ivLength = iv->byteLength(); |
| 575 |
| 576 const unsigned char* additionalDataStart = hasAdditionalData ? static_cast<c
onst unsigned char*>(additionalData->baseAddress()) : 0; |
| 577 unsigned additionalDataLength = hasAdditionalData ? additionalData->byteLeng
th() : 0; |
| 578 |
| 579 params = adoptPtr(new blink::WebCryptoAesGcmParams(ivStart, ivLength, hasAdd
itionalData, additionalDataStart, additionalDataLength, hasTagLength, tagLength)
); |
| 580 return true; |
| 581 } |
| 582 |
456 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, String& errorDetails) | 583 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, String& errorDetails) |
457 { | 584 { |
458 switch (type) { | 585 switch (type) { |
459 case blink::WebCryptoAlgorithmParamsTypeNone: | 586 case blink::WebCryptoAlgorithmParamsTypeNone: |
460 return true; | 587 return true; |
461 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: | 588 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: |
462 context.add("AesCbcParams"); | 589 context.add("AesCbcParams"); |
463 return parseAesCbcParams(raw, params, context, errorDetails); | 590 return parseAesCbcParams(raw, params, context, errorDetails); |
464 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 591 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
465 context.add("AesKeyGenParams"); | 592 context.add("AesKeyGenParams"); |
466 return parseAesKeyGenParams(raw, params, context, errorDetails); | 593 return parseAesKeyGenParams(raw, params, context, errorDetails); |
467 case blink::WebCryptoAlgorithmParamsTypeHmacParams: | 594 case blink::WebCryptoAlgorithmParamsTypeHmacParams: |
468 context.add("HmacParams"); | 595 context.add("HmacParams"); |
469 return parseHmacParams(raw, params, context, errorDetails); | 596 return parseHmacParams(raw, params, context, errorDetails); |
470 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams: | 597 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams: |
471 context.add("HmacKeyParams"); | 598 context.add("HmacKeyParams"); |
472 return parseHmacKeyParams(raw, params, context, errorDetails); | 599 return parseHmacKeyParams(raw, params, context, errorDetails); |
473 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams: | 600 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams: |
474 context.add("RsaSSaParams"); | 601 context.add("RsaSSaParams"); |
475 return parseRsaSsaParams(raw, params, context, errorDetails); | 602 return parseRsaSsaParams(raw, params, context, errorDetails); |
476 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 603 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
477 context.add("RsaKeyGenParams"); | 604 context.add("RsaKeyGenParams"); |
478 return parseRsaKeyGenParams(raw, params, context, errorDetails); | 605 return parseRsaKeyGenParams(raw, params, context, errorDetails); |
479 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: | 606 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: |
480 context.add("AesCtrParams"); | 607 context.add("AesCtrParams"); |
481 return parseAesCtrParams(raw, params, context, errorDetails); | 608 return parseAesCtrParams(raw, params, context, errorDetails); |
482 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: | 609 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
| 610 context.add("AesGcmParams"); |
| 611 return parseAesGcmParams(raw, params, context, errorDetails); |
483 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 612 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
484 // TODO | 613 // TODO |
485 notImplemented(); | 614 notImplemented(); |
486 break; | 615 break; |
487 } | 616 } |
488 ASSERT_NOT_REACHED(); | 617 ASSERT_NOT_REACHED(); |
489 return false; | 618 return false; |
490 } | 619 } |
491 | 620 |
492 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, ErrorContext context, String& errorDetails) | 621 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, ErrorContext context, String& errorDetails) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 666 } |
538 return true; | 667 return true; |
539 } | 668 } |
540 | 669 |
541 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) | 670 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
542 { | 671 { |
543 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; | 672 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; |
544 } | 673 } |
545 | 674 |
546 } // namespace WebCore | 675 } // namespace WebCore |
OLD | NEW |