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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 // AES-CTR | 94 // AES-CTR |
95 {blink::WebCryptoAlgorithmIdAesCtr, Decrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, | 95 {blink::WebCryptoAlgorithmIdAesCtr, Decrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, |
96 {blink::WebCryptoAlgorithmIdAesCtr, Encrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, | 96 {blink::WebCryptoAlgorithmIdAesCtr, Encrypt, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, |
97 {blink::WebCryptoAlgorithmIdAesCtr, GenerateKey, blink::WebCryptoAlgorithmPa
ramsTypeAesKeyGenParams}, | 97 {blink::WebCryptoAlgorithmIdAesCtr, GenerateKey, blink::WebCryptoAlgorithmPa
ramsTypeAesKeyGenParams}, |
98 {blink::WebCryptoAlgorithmIdAesCtr, ImportKey, blink::WebCryptoAlgorithmPara
msTypeNone}, | 98 {blink::WebCryptoAlgorithmIdAesCtr, ImportKey, blink::WebCryptoAlgorithmPara
msTypeNone}, |
99 {blink::WebCryptoAlgorithmIdAesCtr, UnwrapKey, blink::WebCryptoAlgorithmPara
msTypeAesCtrParams}, | 99 {blink::WebCryptoAlgorithmIdAesCtr, UnwrapKey, blink::WebCryptoAlgorithmPara
msTypeAesCtrParams}, |
100 {blink::WebCryptoAlgorithmIdAesCtr, WrapKey, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, | 100 {blink::WebCryptoAlgorithmIdAesCtr, WrapKey, blink::WebCryptoAlgorithmParams
TypeAesCtrParams}, |
101 | 101 |
102 // HMAC | 102 // HMAC |
103 {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeH
macParams}, | 103 {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeN
one}, |
104 {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTyp
eHmacParams}, | 104 {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTyp
eNone}, |
105 {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmPara
msTypeHmacKeyParams}, | 105 {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmPara
msTypeHmacKeyGenParams}, |
106 {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParams
TypeHmacParams}, | 106 {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParams
TypeHmacImportParams}, |
107 | 107 |
108 // RSASSA-PKCS1-v1_5 | 108 // RSASSA-PKCS1-v1_5 |
109 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithm
ParamsTypeRsaSsaParams}, | 109 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithm
ParamsTypeNone}, |
110 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorit
hmParamsTypeRsaSsaParams}, | 110 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
111 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAl
gorithmParamsTypeRsaKeyGenParams}, | 111 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAl
gorithmParamsTypeRsaHashedKeyGenParams}, |
112 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgo
rithmParamsTypeNone}, | 112 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgo
rithmParamsTypeRsaHashedImportParams}, |
113 | 113 |
114 // RSAES-PKCS1-v1_5 | 114 // RSAES-PKCS1-v1_5 |
115 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, | 115 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
116 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Decrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, | 116 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Decrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
117 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, GenerateKey, blink::WebCryptoAlg
orithmParamsTypeRsaKeyGenParams}, | 117 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, GenerateKey, blink::WebCryptoAlg
orithmParamsTypeRsaKeyGenParams}, |
118 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, ImportKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, | 118 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, ImportKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, |
119 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, WrapKey, blink::WebCryptoAlgorit
hmParamsTypeNone}, | 119 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, WrapKey, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
120 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, UnwrapKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, | 120 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, UnwrapKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, |
121 | 121 |
122 // SHA-* | 122 // SHA-* |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 456 |
457 context.add("hash"); | 457 context.add("hash"); |
458 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); | 458 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); |
459 } | 459 } |
460 | 460 |
461 // Defined by the WebCrypto spec as: | 461 // Defined by the WebCrypto spec as: |
462 // | 462 // |
463 // dictionary HmacImportParams : Algorithm { | 463 // dictionary HmacImportParams : Algorithm { |
464 // AlgorithmIdentifier hash; | 464 // AlgorithmIdentifier hash; |
465 // }; | 465 // }; |
466 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ErrorContext& context, String& errorDetails) | 466 bool parseHmacImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, String& errorDetails) |
467 { | 467 { |
468 blink::WebCryptoAlgorithm hash; | 468 blink::WebCryptoAlgorithm hash; |
469 if (!parseHash(raw, hash, context, errorDetails)) | 469 if (!parseHash(raw, hash, context, errorDetails)) |
470 return false; | 470 return false; |
471 | 471 |
472 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); | 472 params = adoptPtr(new blink::WebCryptoHmacImportParams(hash)); |
473 return true; | 473 return true; |
474 } | 474 } |
475 | 475 |
476 // Defined by the WebCrypto spec as: | 476 // Defined by the WebCrypto spec as: |
477 // | 477 // |
478 // dictionary HmacKeyGenParams : Algorithm { | 478 // dictionary HmacKeyGenParams : Algorithm { |
479 // AlgorithmIdentifier hash; | 479 // AlgorithmIdentifier hash; |
480 // // The length (in bytes) of the key to generate. If unspecified, the | 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 | 481 // // recommended length will be used, which is the size of the associated
hash function's block |
482 // // size. | 482 // // size. |
483 // unsigned long length; | 483 // unsigned long length; |
484 // }; | 484 // }; |
485 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, String& errorDetails) | 485 bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, String& errorDetails) |
486 { | 486 { |
487 blink::WebCryptoAlgorithm hash; | 487 blink::WebCryptoAlgorithm hash; |
488 if (!parseHash(raw, hash, context, errorDetails)) | 488 if (!parseHash(raw, hash, context, errorDetails)) |
489 return false; | 489 return false; |
490 | 490 |
491 bool hasLength; | 491 bool hasLength; |
492 uint32_t length = 0; | 492 uint32_t length = 0; |
493 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai
ls)) | 493 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai
ls)) |
494 return false; | 494 return false; |
495 | 495 |
496 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length)
); | 496 params = adoptPtr(new blink::WebCryptoHmacKeyGenParams(hash, hasLength, leng
th)); |
497 return true; | 497 return true; |
498 } | 498 } |
499 | 499 |
500 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) | 500 // Defined by the WebCrypto spec as: |
| 501 // |
| 502 // dictionary RsaHashedImportParams { |
| 503 // AlgorithmIdentifier hash; |
| 504 // }; |
| 505 bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, String& errorDetails) |
501 { | 506 { |
502 blink::WebCryptoAlgorithm hash; | 507 blink::WebCryptoAlgorithm hash; |
503 if (!parseHash(raw, hash, context, errorDetails)) | 508 if (!parseHash(raw, hash, context, errorDetails)) |
504 return false; | 509 return false; |
505 | 510 |
506 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash)); | 511 params = adoptPtr(new blink::WebCryptoRsaHashedImportParams(hash)); |
507 return true; | 512 return true; |
508 } | 513 } |
509 | 514 |
510 // Defined by the WebCrypto spec as: | 515 // Defined by the WebCrypto spec as: |
511 // | 516 // |
512 // dictionary RsaKeyGenParams : Algorithm { | 517 // dictionary RsaKeyGenParams : Algorithm { |
513 // unsigned long modulusLength; | 518 // unsigned long modulusLength; |
514 // BigInteger publicExponent; | 519 // BigInteger publicExponent; |
515 // }; | 520 // }; |
| 521 bool parseRsaKeyGenParams(const Dictionary& raw, uint32_t& modulusLength, RefPtr
<Uint8Array>& publicExponent, const ErrorContext& context, String& errorDetails) |
| 522 { |
| 523 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) |
| 524 return false; |
| 525 |
| 526 if (!getBigInteger(raw, "publicExponent", publicExponent, context, errorDeta
ils)) |
| 527 return false; |
| 528 |
| 529 return true; |
| 530 } |
| 531 |
516 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) | 532 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) |
517 { | 533 { |
518 uint32_t modulusLength; | 534 uint32_t modulusLength; |
519 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) | |
520 return false; | |
521 | |
522 RefPtr<Uint8Array> publicExponent; | 535 RefPtr<Uint8Array> publicExponent; |
523 if (!getBigInteger(raw, "publicExponent", publicExponent, context, errorDeta
ils)) | 536 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, error
Details)) |
524 return false; | 537 return false; |
525 | 538 |
526 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); | 539 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); |
527 return true; | 540 return true; |
528 } | 541 } |
529 | 542 |
530 // Defined by the WebCrypto spec as: | 543 // Defined by the WebCrypto spec as: |
531 // | 544 // |
| 545 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { |
| 546 // AlgorithmIdentifier hash; |
| 547 // }; |
| 548 bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, String& errorDetails) |
| 549 { |
| 550 uint32_t modulusLength; |
| 551 RefPtr<Uint8Array> publicExponent; |
| 552 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, error
Details)) |
| 553 return false; |
| 554 |
| 555 blink::WebCryptoAlgorithm hash; |
| 556 if (!parseHash(raw, hash, context, errorDetails)) |
| 557 return false; |
| 558 |
| 559 params = adoptPtr(new blink::WebCryptoRsaHashedKeyGenParams(hash, modulusLen
gth, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExp
onent->byteLength())); |
| 560 return true; |
| 561 } |
| 562 |
| 563 // Defined by the WebCrypto spec as: |
| 564 // |
532 // dictionary AesCtrParams : Algorithm { | 565 // dictionary AesCtrParams : Algorithm { |
533 // CryptoOperationData counter; | 566 // CryptoOperationData counter; |
534 // [EnforceRange] octet length; | 567 // [EnforceRange] octet length; |
535 // }; | 568 // }; |
536 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) | 569 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, String& errorDetails) |
537 { | 570 { |
538 RefPtr<ArrayBufferView> counter; | 571 RefPtr<ArrayBufferView> counter; |
539 if (!getCryptoOperationData(raw, "counter", counter, context, errorDetails)) | 572 if (!getCryptoOperationData(raw, "counter", counter, context, errorDetails)) |
540 return false; | 573 return false; |
541 | 574 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 { | 617 { |
585 switch (type) { | 618 switch (type) { |
586 case blink::WebCryptoAlgorithmParamsTypeNone: | 619 case blink::WebCryptoAlgorithmParamsTypeNone: |
587 return true; | 620 return true; |
588 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: | 621 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: |
589 context.add("AesCbcParams"); | 622 context.add("AesCbcParams"); |
590 return parseAesCbcParams(raw, params, context, errorDetails); | 623 return parseAesCbcParams(raw, params, context, errorDetails); |
591 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 624 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
592 context.add("AesKeyGenParams"); | 625 context.add("AesKeyGenParams"); |
593 return parseAesKeyGenParams(raw, params, context, errorDetails); | 626 return parseAesKeyGenParams(raw, params, context, errorDetails); |
594 case blink::WebCryptoAlgorithmParamsTypeHmacParams: | 627 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: |
595 context.add("HmacParams"); | 628 context.add("HmacImporParams"); |
596 return parseHmacParams(raw, params, context, errorDetails); | 629 return parseHmacImportParams(raw, params, context, errorDetails); |
597 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams: | 630 case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams: |
598 context.add("HmacKeyParams"); | 631 context.add("HmacKeyGenParams"); |
599 return parseHmacKeyParams(raw, params, context, errorDetails); | 632 return parseHmacKeyGenParams(raw, params, context, errorDetails); |
600 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams: | 633 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: |
601 context.add("RsaSSaParams"); | 634 context.add("RsaHashedKeyGenParams"); |
602 return parseRsaSsaParams(raw, params, context, errorDetails); | 635 return parseRsaHashedKeyGenParams(raw, params, context, errorDetails); |
| 636 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: |
| 637 context.add("RsaHashedImportParams"); |
| 638 return parseRsaHashedImportParams(raw, params, context, errorDetails); |
603 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 639 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
604 context.add("RsaKeyGenParams"); | 640 context.add("RsaKeyGenParams"); |
605 return parseRsaKeyGenParams(raw, params, context, errorDetails); | 641 return parseRsaKeyGenParams(raw, params, context, errorDetails); |
606 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: | 642 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: |
607 context.add("AesCtrParams"); | 643 context.add("AesCtrParams"); |
608 return parseAesCtrParams(raw, params, context, errorDetails); | 644 return parseAesCtrParams(raw, params, context, errorDetails); |
609 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: | 645 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
610 context.add("AesGcmParams"); | 646 context.add("AesGcmParams"); |
611 return parseAesGcmParams(raw, params, context, errorDetails); | 647 return parseAesGcmParams(raw, params, context, errorDetails); |
612 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 648 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 } | 702 } |
667 return true; | 703 return true; |
668 } | 704 } |
669 | 705 |
670 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) | 706 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
671 { | 707 { |
672 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; | 708 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; |
673 } | 709 } |
674 | 710 |
675 } // namespace WebCore | 711 } // namespace WebCore |
OLD | NEW |