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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 // AES-CTR | 93 // AES-CTR |
94 {blink::WebCryptoAlgorithmIdAesCtr, Decrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, | 94 {blink::WebCryptoAlgorithmIdAesCtr, Decrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, |
95 {blink::WebCryptoAlgorithmIdAesCtr, Encrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, | 95 {blink::WebCryptoAlgorithmIdAesCtr, Encrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, |
96 {blink::WebCryptoAlgorithmIdAesCtr, GenerateKey, blink::WebCryptoAlgorithmPa
ramsTypeAesKeyGenParams}, | 96 {blink::WebCryptoAlgorithmIdAesCtr, GenerateKey, blink::WebCryptoAlgorithmPa
ramsTypeAesKeyGenParams}, |
97 {blink::WebCryptoAlgorithmIdAesCtr, ImportKey, blink::WebCryptoAlgorithmPara
msTypeNone}, | 97 {blink::WebCryptoAlgorithmIdAesCtr, ImportKey, blink::WebCryptoAlgorithmPara
msTypeNone}, |
98 {blink::WebCryptoAlgorithmIdAesCtr, UnwrapKey, blink::WebCryptoAlgorithmPara
msTypeAesCtrParams}, | 98 {blink::WebCryptoAlgorithmIdAesCtr, UnwrapKey, blink::WebCryptoAlgorithmPara
msTypeAesCtrParams}, |
99 {blink::WebCryptoAlgorithmIdAesCtr, WrapKey, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, | 99 {blink::WebCryptoAlgorithmIdAesCtr, WrapKey, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, |
100 | 100 |
101 // HMAC | 101 // HMAC |
102 {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeH
macParams}, | 102 {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeN
one}, |
103 {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTyp
eHmacParams}, | 103 {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTyp
eNone}, |
104 {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmPara
msTypeHmacKeyParams}, | 104 {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmPara
msTypeHmacKeyGenParams}, |
105 {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParams
TypeHmacParams}, | 105 {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParams
TypeHmacImportParams}, |
106 | 106 |
107 // RSASSA-PKCS1-v1_5 | 107 // RSASSA-PKCS1-v1_5 |
108 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithm
ParamsTypeRsaSsaParams}, | 108 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithm
ParamsTypeNone}, |
109 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorit
hmParamsTypeRsaSsaParams}, | 109 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
110 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAl
gorithmParamsTypeRsaKeyGenParams}, | 110 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAl
gorithmParamsTypeRsaHashedKeyGenParams}, |
111 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgo
rithmParamsTypeNone}, | 111 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgo
rithmParamsTypeRsaHashedImportParams}, |
112 | 112 |
113 // RSAES-PKCS1-v1_5 | 113 // RSAES-PKCS1-v1_5 |
114 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, | 114 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
115 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Decrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, | 115 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Decrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
116 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, GenerateKey, blink::WebCryptoAlg
orithmParamsTypeRsaKeyGenParams}, | 116 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, GenerateKey, blink::WebCryptoAlg
orithmParamsTypeRsaKeyGenParams}, |
117 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, ImportKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, | 117 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, ImportKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, |
118 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, WrapKey, blink::WebCryptoAlgorit
hmParamsTypeNone}, | 118 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, WrapKey, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
119 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, UnwrapKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, | 119 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, UnwrapKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, |
120 | 120 |
121 // SHA-* | 121 // SHA-* |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 Dictionary rawHash; | 383 Dictionary rawHash; |
384 if (!raw.get("hash", rawHash)) { | 384 if (!raw.get("hash", rawHash)) { |
385 errorDetails = context.toString("hash", "Missing or not a dictionary"); | 385 errorDetails = context.toString("hash", "Missing or not a dictionary"); |
386 return false; | 386 return false; |
387 } | 387 } |
388 | 388 |
389 context.add("hash"); | 389 context.add("hash"); |
390 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); | 390 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); |
391 } | 391 } |
392 | 392 |
393 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ErrorContext& context, String& errorDetails) | 393 bool parseHmacImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, String& errorDetails) |
394 { | 394 { |
395 blink::WebCryptoAlgorithm hash; | 395 blink::WebCryptoAlgorithm hash; |
396 if (!parseHash(raw, hash, context, errorDetails)) | 396 if (!parseHash(raw, hash, context, errorDetails)) |
397 return false; | 397 return false; |
398 | 398 |
399 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); | 399 params = adoptPtr(new blink::WebCryptoHmacImportParams(hash)); |
400 return true; | 400 return true; |
401 } | 401 } |
402 | 402 |
403 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, String& errorDetails) | 403 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, String& errorDetails) |
404 { | 404 { |
405 blink::WebCryptoAlgorithm hash; | 405 blink::WebCryptoAlgorithm hash; |
406 if (!parseHash(raw, hash, context, errorDetails)) | 406 if (!parseHash(raw, hash, context, errorDetails)) |
407 return false; | 407 return false; |
408 | 408 |
409 bool hasLength; | 409 bool hasLength; |
410 uint32_t length = 0; | 410 uint32_t length = 0; |
411 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai
ls)) | 411 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai
ls)) |
412 return false; | 412 return false; |
413 | 413 |
414 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length)
); | 414 params = adoptPtr(new blink::WebCryptoHmacKeyGenParams(hash, hasLength, leng
th)); |
415 return true; | 415 return true; |
416 } | 416 } |
417 | 417 |
418 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) | 418 bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, String& errorDetails) |
419 { | 419 { |
420 blink::WebCryptoAlgorithm hash; | 420 blink::WebCryptoAlgorithm hash; |
421 if (!parseHash(raw, hash, context, errorDetails)) | 421 if (!parseHash(raw, hash, context, errorDetails)) |
422 return false; | 422 return false; |
423 | 423 |
424 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash)); | 424 params = adoptPtr(new blink::WebCryptoRsaHashedImportParams(hash)); |
| 425 return true; |
| 426 } |
| 427 |
| 428 bool parseRsaKeyGenParams(const Dictionary& raw, uint32_t& modulusLength, RefPtr
<Uint8Array>& publicExponent, const ErrorContext& context, String& errorDetails) |
| 429 { |
| 430 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) |
| 431 return false; |
| 432 |
| 433 if (!getUint8Array(raw, "publicExponent", publicExponent, context, errorDeta
ils)) |
| 434 return false; |
| 435 |
425 return true; | 436 return true; |
426 } | 437 } |
427 | 438 |
428 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) | 439 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) |
429 { | 440 { |
430 uint32_t modulusLength; | 441 uint32_t modulusLength; |
431 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) | |
432 return false; | |
433 | |
434 RefPtr<Uint8Array> publicExponent; | 442 RefPtr<Uint8Array> publicExponent; |
435 if (!getUint8Array(raw, "publicExponent", publicExponent, context, errorDeta
ils)) | 443 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, error
Details)) |
436 return false; | 444 return false; |
437 | 445 |
438 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); | 446 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); |
439 return true; | 447 return true; |
440 } | 448 } |
441 | 449 |
| 450 bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, String& errorDetails) |
| 451 { |
| 452 uint32_t modulusLength; |
| 453 RefPtr<Uint8Array> publicExponent; |
| 454 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, error
Details)) |
| 455 return false; |
| 456 |
| 457 blink::WebCryptoAlgorithm hash; |
| 458 if (!parseHash(raw, hash, context, errorDetails)) |
| 459 return false; |
| 460 |
| 461 params = adoptPtr(new blink::WebCryptoRsaHashedKeyGenParams(hash, modulusLen
gth, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExp
onent->byteLength())); |
| 462 return true; |
| 463 } |
| 464 |
442 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& es) | 465 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& es) |
443 { | 466 { |
444 RefPtr<Uint8Array> counter; | 467 RefPtr<Uint8Array> counter; |
445 if (!getUint8Array(raw, "counter", counter, context, es)) | 468 if (!getUint8Array(raw, "counter", counter, context, es)) |
446 return false; | 469 return false; |
447 | 470 |
448 uint8_t length; | 471 uint8_t length; |
449 if (!getUint8(raw, "length", length, context, es)) | 472 if (!getUint8(raw, "length", length, context, es)) |
450 return false; | 473 return false; |
451 | 474 |
452 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const
unsigned char*>(counter->baseAddress()), counter->byteLength())); | 475 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const
unsigned char*>(counter->baseAddress()), counter->byteLength())); |
453 return true; | 476 return true; |
454 } | 477 } |
455 | 478 |
456 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, String& errorDetails) | 479 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, String& errorDetails) |
457 { | 480 { |
458 switch (type) { | 481 switch (type) { |
459 case blink::WebCryptoAlgorithmParamsTypeNone: | 482 case blink::WebCryptoAlgorithmParamsTypeNone: |
460 return true; | 483 return true; |
461 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: | 484 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: |
462 context.add("AesCbcParams"); | 485 context.add("AesCbcParams"); |
463 return parseAesCbcParams(raw, params, context, errorDetails); | 486 return parseAesCbcParams(raw, params, context, errorDetails); |
464 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 487 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
465 context.add("AesKeyGenParams"); | 488 context.add("AesKeyGenParams"); |
466 return parseAesKeyGenParams(raw, params, context, errorDetails); | 489 return parseAesKeyGenParams(raw, params, context, errorDetails); |
467 case blink::WebCryptoAlgorithmParamsTypeHmacParams: | 490 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: |
468 context.add("HmacParams"); | 491 context.add("HmacImporParams"); |
469 return parseHmacParams(raw, params, context, errorDetails); | 492 return parseHmacImportParams(raw, params, context, errorDetails); |
470 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams: | 493 case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams: |
471 context.add("HmacKeyParams"); | 494 context.add("HmacKeyGenParams"); |
472 return parseHmacKeyParams(raw, params, context, errorDetails); | 495 return parseHmacKeyParams(raw, params, context, errorDetails); |
473 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams: | 496 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: |
474 context.add("RsaSSaParams"); | 497 context.add("RsaHashedKeyGenParams"); |
475 return parseRsaSsaParams(raw, params, context, errorDetails); | 498 return parseRsaHashedKeyGenParams(raw, params, context, errorDetails); |
| 499 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: |
| 500 context.add("RsaHashedImportParams"); |
| 501 return parseRsaHashedImportParams(raw, params, context, errorDetails); |
476 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 502 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
477 context.add("RsaKeyGenParams"); | 503 context.add("RsaKeyGenParams"); |
478 return parseRsaKeyGenParams(raw, params, context, errorDetails); | 504 return parseRsaKeyGenParams(raw, params, context, errorDetails); |
479 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: | 505 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: |
480 context.add("AesCtrParams"); | 506 context.add("AesCtrParams"); |
481 return parseAesCtrParams(raw, params, context, errorDetails); | 507 return parseAesCtrParams(raw, params, context, errorDetails); |
482 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: | 508 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
483 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 509 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
484 // TODO | 510 // TODO |
485 notImplemented(); | 511 notImplemented(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 563 } |
538 return true; | 564 return true; |
539 } | 565 } |
540 | 566 |
541 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) | 567 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
542 { | 568 { |
543 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; | 569 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; |
544 } | 570 } |
545 | 571 |
546 } // namespace WebCore | 572 } // namespace WebCore |
OLD | NEW |