Changeset 213628 in webkit


Ignore:
Timestamp:
Mar 8, 2017 9:50:31 PM (7 years ago)
Author:
jiewen_tan@apple.com
Message:

[WebCrypto] Implement SubtleCrypto::DeriveKey method
https://bugs.webkit.org/show_bug.cgi?id=169386
<rdar://problem/23789585>

Reviewed by Brent Fulgham.

Source/WebCore:

This patch does following few things:

  1. It implements SubtleCrypto::DeriveKey method according to the spec:

https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-deriveKey.

  1. It implements getKeyLength operations for AES-CBC, AES-KW, AES-CFB,

AES-GCM, and HMAC, which is needed by the SubtleCrypto::DeriveKey method.

  1. It enables ECDH DeriveKey operation.
  2. It replaces unigned long with size_t in all the crypto codes.

Tests: crypto/subtle/derive-key-malformed-parameters.html

crypto/subtle/ecdh-import-key-derive-aes-key.html
crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html
crypto/subtle/unwrap-key-malformed-parameters.html
crypto/subtle/wrap-key-malformed-parameters.html
crypto/workers/subtle/ecdh-import-key-derive-key.html

  • CMakeLists.txt:
  • DerivedSources.make:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSSubtleCryptoCustom.cpp:

(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::jsSubtleCryptoFunctionEncryptPromise):
(WebCore::jsSubtleCryptoFunctionDecryptPromise):
(WebCore::jsSubtleCryptoFunctionSignPromise):
(WebCore::jsSubtleCryptoFunctionVerifyPromise):
(WebCore::jsSubtleCryptoFunctionDigestPromise):
(WebCore::jsSubtleCryptoFunctionDeriveKeyPromise):
(WebCore::jsSubtleCryptoFunctionDeriveBitsPromise):
Remove unnecessary return statement from callbacks.

  • crypto/CryptoAlgorithm.cpp:

(WebCore::CryptoAlgorithm::deriveBits):
(WebCore::CryptoAlgorithm::getKeyLength):

  • crypto/CryptoAlgorithm.h:
  • crypto/CryptoAlgorithmParameters.h:
  • crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:

(WebCore::CryptoAlgorithmAES_CBC::generateKey):
(WebCore::CryptoAlgorithmAES_CBC::getKeyLength):

  • crypto/algorithms/CryptoAlgorithmAES_CBC.h:
  • crypto/algorithms/CryptoAlgorithmAES_CFB.cpp:

(WebCore::CryptoAlgorithmAES_CFB::generateKey):
(WebCore::CryptoAlgorithmAES_CFB::getKeyLength):

  • crypto/algorithms/CryptoAlgorithmAES_CFB.h:
  • crypto/algorithms/CryptoAlgorithmAES_GCM.cpp:

(WebCore::CryptoAlgorithmAES_GCM::generateKey):
(WebCore::CryptoAlgorithmAES_GCM::getKeyLength):

  • crypto/algorithms/CryptoAlgorithmAES_GCM.h:
  • crypto/algorithms/CryptoAlgorithmAES_KW.cpp:

(WebCore::CryptoAlgorithmAES_KW::generateKey):
(WebCore::CryptoAlgorithmAES_KW::getKeyLength):

  • crypto/algorithms/CryptoAlgorithmAES_KW.h:
  • crypto/algorithms/CryptoAlgorithmECDH.cpp:

(WebCore::CryptoAlgorithmECDH::deriveBits):

  • crypto/algorithms/CryptoAlgorithmECDH.h:
  • crypto/algorithms/CryptoAlgorithmHMAC.cpp:

(WebCore::CryptoAlgorithmHMAC::getKeyLength):

  • crypto/algorithms/CryptoAlgorithmHMAC.h:
  • crypto/keys/CryptoKeyAES.cpp:

(WebCore::CryptoKeyAES::getKeyLength):

  • crypto/keys/CryptoKeyAES.h:
  • crypto/keys/CryptoKeyHMAC.cpp:

(WebCore::getKeyLengthFromHash):
(WebCore::CryptoKeyHMAC::generate):
(WebCore::CryptoKeyHMAC::getKeyLength):

  • crypto/keys/CryptoKeyHMAC.h:
  • crypto/mac/CryptoAlgorithmECDHMac.cpp:

(WebCore::CryptoAlgorithmECDH::platformDeriveBits):

  • crypto/parameters/AesKeyParams.idl: Renamed from Source/WebCore/crypto/parameters/AesKeyGenParams.idl.
  • crypto/parameters/CryptoAlgorithmAesKeyParams.h: Renamed from Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h.

Rename AesKeyGenParams to AesKeyParams to represent a unified dictionary for AesKeyGenParams and AesDerivedKeyParams.

  • crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
  • crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:

LayoutTests:

  • crypto/subtle/aes-generate-key-malformed-parameters-expected.txt:
  • crypto/subtle/derive-key-malformed-parameters-expected.txt: Added.
  • crypto/subtle/derive-key-malformed-parameters.html: Added.
  • crypto/subtle/deriveKey-malformed-parameters-expected.txt: Removed.
  • crypto/subtle/deriveKey-malformed-parameters.html: Removed.
  • crypto/subtle/ecdh-import-key-derive-aes-key-expected.txt: Added.
  • crypto/subtle/ecdh-import-key-derive-aes-key.html: Added.
  • crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length-expected.txt: Added.
  • crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html: Added.
  • crypto/subtle/unwrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters-expected.txt.
  • crypto/subtle/unwrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters.html.
  • crypto/subtle/wrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters-expected.txt.
  • crypto/subtle/wrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters.html.

A bit renaming.

  • crypto/workers/subtle/ecdh-import-key-derive-key-expected.txt: Added.
  • crypto/workers/subtle/ecdh-import-key-derive-key.html: Added.
  • crypto/workers/subtle/resources/ecdh-import-key-derive-key.js: Added.
Location:
trunk
Files:
9 added
2 deleted
29 edited
6 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r213626 r213628  
     12017-03-08  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        [WebCrypto] Implement SubtleCrypto::DeriveKey method
     4        https://bugs.webkit.org/show_bug.cgi?id=169386
     5        <rdar://problem/23789585>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * crypto/subtle/aes-generate-key-malformed-parameters-expected.txt:
     10        * crypto/subtle/derive-key-malformed-parameters-expected.txt: Added.
     11        * crypto/subtle/derive-key-malformed-parameters.html: Added.
     12        * crypto/subtle/deriveKey-malformed-parameters-expected.txt: Removed.
     13        * crypto/subtle/deriveKey-malformed-parameters.html: Removed.
     14        * crypto/subtle/ecdh-import-key-derive-aes-key-expected.txt: Added.
     15        * crypto/subtle/ecdh-import-key-derive-aes-key.html: Added.
     16        * crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length-expected.txt: Added.
     17        * crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html: Added.
     18        * crypto/subtle/unwrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters-expected.txt.
     19        * crypto/subtle/unwrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters.html.
     20        * crypto/subtle/wrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters-expected.txt.
     21        * crypto/subtle/wrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters.html.
     22        A bit renaming.
     23        * crypto/workers/subtle/ecdh-import-key-derive-key-expected.txt: Added.
     24        * crypto/workers/subtle/ecdh-import-key-derive-key.html: Added.
     25        * crypto/workers/subtle/resources/ecdh-import-key-derive-key.js: Added.
     26
    1272017-03-08  Matt Baker  <mattbaker@apple.com>
    228
  • trunk/LayoutTests/crypto/subtle/aes-generate-key-malformed-parameters-expected.txt

    r213345 r213628  
    44
    55
    6 PASS crypto.subtle.generateKey("aes-cbc", extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member AesKeyGenParams.length is required and must be an instance of unsigned short.
    7 PASS crypto.subtle.generateKey({name: "aes-cbc"}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member AesKeyGenParams.length is required and must be an instance of unsigned short.
     6PASS crypto.subtle.generateKey("aes-cbc", extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member AesKeyParams.length is required and must be an instance of unsigned short.
     7PASS crypto.subtle.generateKey({name: "aes-cbc"}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member AesKeyParams.length is required and must be an instance of unsigned short.
    88PASS crypto.subtle.generateKey({name: "aes-cbc", length: true}, extractable, ["encrypt", "decrypt"]) rejected promise  with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
    99PASS crypto.subtle.generateKey({name: "aes-cbc", length: null}, extractable, ["encrypt", "decrypt"]) rejected promise  with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
    10 PASS crypto.subtle.generateKey({name: "aes-cbc", length: undefined}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member AesKeyGenParams.length is required and must be an instance of unsigned short.
     10PASS crypto.subtle.generateKey({name: "aes-cbc", length: undefined}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Member AesKeyParams.length is required and must be an instance of unsigned short.
    1111PASS crypto.subtle.generateKey({name: "aes-cbc", length: Symbol()}, extractable, ["encrypt", "decrypt"]) rejected promise  with TypeError: Cannot convert a symbol to a number.
    1212PASS crypto.subtle.generateKey({name: "aes-cbc", length: { }}, extractable, ["encrypt", "decrypt"]) rejected promise  with OperationError (DOM Exception 34): The operation failed for an operation-specific reason.
  • trunk/Source/WebCore/CMakeLists.txt

    r213624 r213628  
    343343    crypto/parameters/AesCbcCfbParams.idl
    344344    crypto/parameters/AesGcmParams.idl
    345     crypto/parameters/AesKeyGenParams.idl
     345    crypto/parameters/AesKeyParams.idl
    346346    crypto/parameters/EcKeyParams.idl
    347347    crypto/parameters/EcdhKeyDeriveParams.idl
  • trunk/Source/WebCore/ChangeLog

    r213627 r213628  
     12017-03-08  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        [WebCrypto] Implement SubtleCrypto::DeriveKey method
     4        https://bugs.webkit.org/show_bug.cgi?id=169386
     5        <rdar://problem/23789585>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This patch does following few things:
     10        1. It implements SubtleCrypto::DeriveKey method according to the spec:
     11        https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-deriveKey.
     12        2. It implements getKeyLength operations for AES-CBC, AES-KW, AES-CFB,
     13        AES-GCM, and HMAC, which is needed by the SubtleCrypto::DeriveKey method.
     14        3. It enables ECDH DeriveKey operation.
     15        4. It replaces unigned long with size_t in all the crypto codes.
     16
     17        Tests: crypto/subtle/derive-key-malformed-parameters.html
     18               crypto/subtle/ecdh-import-key-derive-aes-key.html
     19               crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html
     20               crypto/subtle/unwrap-key-malformed-parameters.html
     21               crypto/subtle/wrap-key-malformed-parameters.html
     22               crypto/workers/subtle/ecdh-import-key-derive-key.html
     23
     24        * CMakeLists.txt:
     25        * DerivedSources.make:
     26        * WebCore.xcodeproj/project.pbxproj:
     27        * bindings/js/JSSubtleCryptoCustom.cpp:
     28        (WebCore::normalizeCryptoAlgorithmParameters):
     29        (WebCore::jsSubtleCryptoFunctionEncryptPromise):
     30        (WebCore::jsSubtleCryptoFunctionDecryptPromise):
     31        (WebCore::jsSubtleCryptoFunctionSignPromise):
     32        (WebCore::jsSubtleCryptoFunctionVerifyPromise):
     33        (WebCore::jsSubtleCryptoFunctionDigestPromise):
     34        (WebCore::jsSubtleCryptoFunctionDeriveKeyPromise):
     35        (WebCore::jsSubtleCryptoFunctionDeriveBitsPromise):
     36        Remove unnecessary return statement from callbacks.
     37        * crypto/CryptoAlgorithm.cpp:
     38        (WebCore::CryptoAlgorithm::deriveBits):
     39        (WebCore::CryptoAlgorithm::getKeyLength):
     40        * crypto/CryptoAlgorithm.h:
     41        * crypto/CryptoAlgorithmParameters.h:
     42        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
     43        (WebCore::CryptoAlgorithmAES_CBC::generateKey):
     44        (WebCore::CryptoAlgorithmAES_CBC::getKeyLength):
     45        * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
     46        * crypto/algorithms/CryptoAlgorithmAES_CFB.cpp:
     47        (WebCore::CryptoAlgorithmAES_CFB::generateKey):
     48        (WebCore::CryptoAlgorithmAES_CFB::getKeyLength):
     49        * crypto/algorithms/CryptoAlgorithmAES_CFB.h:
     50        * crypto/algorithms/CryptoAlgorithmAES_GCM.cpp:
     51        (WebCore::CryptoAlgorithmAES_GCM::generateKey):
     52        (WebCore::CryptoAlgorithmAES_GCM::getKeyLength):
     53        * crypto/algorithms/CryptoAlgorithmAES_GCM.h:
     54        * crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
     55        (WebCore::CryptoAlgorithmAES_KW::generateKey):
     56        (WebCore::CryptoAlgorithmAES_KW::getKeyLength):
     57        * crypto/algorithms/CryptoAlgorithmAES_KW.h:
     58        * crypto/algorithms/CryptoAlgorithmECDH.cpp:
     59        (WebCore::CryptoAlgorithmECDH::deriveBits):
     60        * crypto/algorithms/CryptoAlgorithmECDH.h:
     61        * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
     62        (WebCore::CryptoAlgorithmHMAC::getKeyLength):
     63        * crypto/algorithms/CryptoAlgorithmHMAC.h:
     64        * crypto/keys/CryptoKeyAES.cpp:
     65        (WebCore::CryptoKeyAES::getKeyLength):
     66        * crypto/keys/CryptoKeyAES.h:
     67        * crypto/keys/CryptoKeyHMAC.cpp:
     68        (WebCore::getKeyLengthFromHash):
     69        (WebCore::CryptoKeyHMAC::generate):
     70        (WebCore::CryptoKeyHMAC::getKeyLength):
     71        * crypto/keys/CryptoKeyHMAC.h:
     72        * crypto/mac/CryptoAlgorithmECDHMac.cpp:
     73        (WebCore::CryptoAlgorithmECDH::platformDeriveBits):
     74        * crypto/parameters/AesKeyParams.idl: Renamed from Source/WebCore/crypto/parameters/AesKeyGenParams.idl.
     75        * crypto/parameters/CryptoAlgorithmAesKeyParams.h: Renamed from Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h.
     76        Rename AesKeyGenParams to AesKeyParams to represent a unified dictionary for AesKeyGenParams and AesDerivedKeyParams.
     77        * crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
     78        * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
     79
    1802017-03-08  Wenson Hsieh  <wenson_hsieh@apple.com>
    281
  • trunk/Source/WebCore/DerivedSources.make

    r213624 r213628  
    275275    $(WebCore)/crypto/parameters/AesCbcCfbParams.idl \
    276276    $(WebCore)/crypto/parameters/AesGcmParams.idl \
    277     $(WebCore)/crypto/parameters/AesKeyGenParams.idl \
     277    $(WebCore)/crypto/parameters/AesKeyParams.idl \
    278278    $(WebCore)/crypto/parameters/EcKeyParams.idl \
    279279    $(WebCore)/crypto/parameters/EcdhKeyDeriveParams.idl \
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r213624 r213628  
    23832383                576814401E709FA100E77754 /* JSEcdhKeyDeriveParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5768143D1E709C3600E77754 /* JSEcdhKeyDeriveParams.cpp */; };
    23842384                576814411E709FA400E77754 /* JSEcdhKeyDeriveParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 5768143E1E709C3600E77754 /* JSEcdhKeyDeriveParams.h */; };
     2385                576814441E70CB1B00E77754 /* JSAesKeyParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 576814421E70CB1000E77754 /* JSAesKeyParams.cpp */; };
     2386                576814451E70CB1F00E77754 /* JSAesKeyParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 576814431E70CB1000E77754 /* JSAesKeyParams.h */; };
    23852387                5768E4341DB7524500D0A4F7 /* JSRsaHashedKeyGenParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 5768E4331DB7524500D0A4F7 /* JSRsaHashedKeyGenParams.h */; };
    23862388                5768E4361DB7527400D0A4F7 /* JSRsaHashedKeyGenParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5768E4351DB7527300D0A4F7 /* JSRsaHashedKeyGenParams.cpp */; };
    2387                 577483121DADC55D00716EF9 /* CryptoAlgorithmAesKeyGenParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 577483111DADC55D00716EF9 /* CryptoAlgorithmAesKeyGenParams.h */; };
    2388                 577483141DAEC2EB00716EF9 /* JSAesKeyGenParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 577483131DAEC2EA00716EF9 /* JSAesKeyGenParams.h */; };
    2389                 577483161DAEC32300716EF9 /* JSAesKeyGenParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 577483151DAEC32200716EF9 /* JSAesKeyGenParams.cpp */; };
     2389                577483121DADC55D00716EF9 /* CryptoAlgorithmAesKeyParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 577483111DADC55D00716EF9 /* CryptoAlgorithmAesKeyParams.h */; };
    23902390                577483191DB4491F00716EF9 /* CryptoAlgorithmHmacKeyParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 577483181DB4491F00716EF9 /* CryptoAlgorithmHmacKeyParams.h */; };
    23912391                5778BD821DA4806C009E3009 /* SubtleCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 5778BD811DA4802C009E3009 /* SubtleCrypto.h */; };
     
    98179817                5768143D1E709C3600E77754 /* JSEcdhKeyDeriveParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSEcdhKeyDeriveParams.cpp; sourceTree = "<group>"; };
    98189818                5768143E1E709C3600E77754 /* JSEcdhKeyDeriveParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEcdhKeyDeriveParams.h; sourceTree = "<group>"; };
     9819                576814421E70CB1000E77754 /* JSAesKeyParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAesKeyParams.cpp; sourceTree = "<group>"; };
     9820                576814431E70CB1000E77754 /* JSAesKeyParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAesKeyParams.h; sourceTree = "<group>"; };
    98199821                5768E4331DB7524500D0A4F7 /* JSRsaHashedKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRsaHashedKeyGenParams.h; sourceTree = "<group>"; };
    98209822                5768E4351DB7527300D0A4F7 /* JSRsaHashedKeyGenParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRsaHashedKeyGenParams.cpp; sourceTree = "<group>"; };
    9821                 577483101DADC49900716EF9 /* AesKeyGenParams.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AesKeyGenParams.idl; sourceTree = "<group>"; };
    9822                 577483111DADC55D00716EF9 /* CryptoAlgorithmAesKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmAesKeyGenParams.h; sourceTree = "<group>"; };
    9823                 577483131DAEC2EA00716EF9 /* JSAesKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAesKeyGenParams.h; sourceTree = "<group>"; };
    9824                 577483151DAEC32200716EF9 /* JSAesKeyGenParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAesKeyGenParams.cpp; sourceTree = "<group>"; };
     9823                577483101DADC49900716EF9 /* AesKeyParams.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AesKeyParams.idl; sourceTree = "<group>"; };
     9824                577483111DADC55D00716EF9 /* CryptoAlgorithmAesKeyParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmAesKeyParams.h; sourceTree = "<group>"; };
    98259825                577483171DB1FE8900716EF9 /* HmacKeyParams.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = HmacKeyParams.idl; sourceTree = "<group>"; };
    98269826                577483181DB4491F00716EF9 /* CryptoAlgorithmHmacKeyParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmHmacKeyParams.h; sourceTree = "<group>"; };
     
    1000210002                5DB1BC6910715A6400EFAA49 /* TransformSourceLibxslt.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TransformSourceLibxslt.cpp; sourceTree = "<group>"; };
    1000310003                5DFEBAB618592B6D00C75BEB /* WebKitAvailability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAvailability.h; sourceTree = "<group>"; };
    10004                 5E16A2E21BFA64FB0029A21E /* MediaEndpointPeerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = MediaEndpointPeerConnection.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
    10005                 5E16A2E31BFA64FB0029A21E /* MediaEndpointPeerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = MediaEndpointPeerConnection.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
     10004                5E16A2E21BFA64FB0029A21E /* MediaEndpointPeerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaEndpointPeerConnection.cpp; sourceTree = "<group>"; };
     10005                5E16A2E31BFA64FB0029A21E /* MediaEndpointPeerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaEndpointPeerConnection.h; sourceTree = "<group>"; };
    1000610006                5E2C434D1BCEE2E50001E2BC /* PeerConnectionBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeerConnectionBackend.h; sourceTree = "<group>"; };
    1000710007                5E2C43541BCEE30D0001E2BC /* RTCPeerConnection.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = RTCPeerConnection.js; sourceTree = "<group>"; };
     
    2368323683                                572093D11DDCEA4B00310AB0 /* AesCbcCfbParams.idl */,
    2368423684                                57B5F8071E5D19F200F34F90 /* AesGcmParams.idl */,
    23685                                 577483101DADC49900716EF9 /* AesKeyGenParams.idl */,
     23685                                577483101DADC49900716EF9 /* AesKeyParams.idl */,
    2368623686                                572093D21DDCEB9A00310AB0 /* CryptoAlgorithmAesCbcCfbParams.h */,
    2368723687                                E125F8391824104800D84CD9 /* CryptoAlgorithmAesCbcParamsDeprecated.h */,
    2368823688                                57B5F8081E5D1A9800F34F90 /* CryptoAlgorithmAesGcmParams.h */,
    23689                                 577483111DADC55D00716EF9 /* CryptoAlgorithmAesKeyGenParams.h */,
     23689                                577483111DADC55D00716EF9 /* CryptoAlgorithmAesKeyParams.h */,
    2369023690                                E19AC3F61824E5D100349426 /* CryptoAlgorithmAesKeyGenParamsDeprecated.h */,
    2369123691                                5750A97D1E6A13EF00705C4A /* CryptoAlgorithmEcKeyParams.h */,
     
    2386823868                                57B5F80A1E5D22DA00F34F90 /* JSAesGcmParams.cpp */,
    2386923869                                57B5F80B1E5D22DA00F34F90 /* JSAesGcmParams.h */,
    23870                                 577483151DAEC32200716EF9 /* JSAesKeyGenParams.cpp */,
    23871                                 577483131DAEC2EA00716EF9 /* JSAesKeyGenParams.h */,
     23870                                576814421E70CB1000E77754 /* JSAesKeyParams.cpp */,
     23871                                576814431E70CB1000E77754 /* JSAesKeyParams.h */,
    2387223872                                5739E1301DAC7FD100E14383 /* JSCryptoAlgorithmParameters.cpp */,
    2387323873                                5739E12E1DAC7F7800E14383 /* JSCryptoAlgorithmParameters.h */,
     
    2588325883                                572093D31DDCEB9A00310AB0 /* CryptoAlgorithmAesCbcCfbParams.h in Headers */,
    2588425884                                E125F83A1824104800D84CD9 /* CryptoAlgorithmAesCbcParamsDeprecated.h in Headers */,
    25885                                 577483121DADC55D00716EF9 /* CryptoAlgorithmAesKeyGenParams.h in Headers */,
     25885                                577483121DADC55D00716EF9 /* CryptoAlgorithmAesKeyParams.h in Headers */,
    2588625886                                E19AC3F71824E5D100349426 /* CryptoAlgorithmAesKeyGenParamsDeprecated.h in Headers */,
    2588725887                                E125F8321822F11B00D84CD9 /* CryptoAlgorithmHMAC.h in Headers */,
     
    2673826738                                07AC47021952102100EE9723 /* ISOVTTCue.h in Headers */,
    2673926739                                418F88050FF957AF0080F045 /* JSAbstractWorker.h in Headers */,
    26740                                 577483141DAEC2EB00716EF9 /* JSAesKeyGenParams.h in Headers */,
    2674126740                                FDA15ECA12B03F50003A583A /* JSAnalyserNode.h in Headers */,
    2674226741                                12A253E31C8FFF6600C22295 /* JSAnimatable.h in Headers */,
     
    2675026749                                7C6523181E00DBB500677F22 /* JSApplePayPaymentMethod.h in Headers */,
    2675126750                                1AE96A8D1D1A0DDD00B86768 /* JSApplePayPaymentMethodSelectedEvent.h in Headers */,
     26751                                576814451E70CB1F00E77754 /* JSAesKeyParams.h in Headers */,
    2675226752                                7C65231A1E00DBB500677F22 /* JSApplePayPaymentPass.h in Headers */,
    2675326753                                7C6579F21E00856600E3A27A /* JSApplePayPaymentRequest.h in Headers */,
     
    3058530585                                07AC47011952102100EE9723 /* ISOVTTCue.cpp in Sources */,
    3058630586                                418F88040FF957AE0080F045 /* JSAbstractWorker.cpp in Sources */,
    30587                                 577483161DAEC32300716EF9 /* JSAesKeyGenParams.cpp in Sources */,
    3058830587                                FDA15EC912B03F50003A583A /* JSAnalyserNode.cpp in Sources */,
    3058930588                                31A795C61888BADC00382F90 /* JSANGLEInstancedArrays.cpp in Sources */,
     
    3084830847                                A6148A7812E41E3B0044A784 /* JSHTMLKeygenElement.cpp in Sources */,
    3084930848                                1AE2AB210A1CE63B00B42B25 /* JSHTMLLabelElement.cpp in Sources */,
     30849                                576814441E70CB1B00E77754 /* JSAesKeyParams.cpp in Sources */,
    3085030850                                1AE2AB230A1CE63B00B42B25 /* JSHTMLLegendElement.cpp in Sources */,
    3085130851                                1AE2AB250A1CE63B00B42B25 /* JSHTMLLIElement.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp

    r213624 r213628  
    3333#include "JSAesCbcCfbParams.h"
    3434#include "JSAesGcmParams.h"
    35 #include "JSAesKeyGenParams.h"
     35#include "JSAesKeyParams.h"
    3636#include "JSCryptoAlgorithmParameters.h"
    3737#include "JSCryptoKey.h"
     
    6262    Verify,
    6363    Digest,
    64     DeriveKey,
     64    GenerateKey,
    6565    DeriveBits,
    66     GenerateKey,
    6766    ImportKey,
    6867    WrapKey,
    69     UnwrapKey
     68    UnwrapKey,
     69    GetKeyLength
    7070};
    7171
     
    161161            }
    162162            break;
    163         case Operations::DeriveKey:
    164             throwNotSupportedError(state, scope);
    165             return nullptr;
    166163        case Operations::DeriveBits:
    167164            switch (*identifier) {
     
    208205            case CryptoAlgorithmIdentifier::AES_CFB:
    209206            case CryptoAlgorithmIdentifier::AES_KW: {
    210                 auto params = convertDictionary<CryptoAlgorithmAesKeyGenParams>(state, value);
    211                 RETURN_IF_EXCEPTION(scope, nullptr);
    212                 result = std::make_unique<CryptoAlgorithmAesKeyGenParams>(params);
     207                auto params = convertDictionary<CryptoAlgorithmAesKeyParams>(state, value);
     208                RETURN_IF_EXCEPTION(scope, nullptr);
     209                result = std::make_unique<CryptoAlgorithmAesKeyParams>(params);
    213210                break;
    214211            }
     
    282279                result = std::make_unique<CryptoAlgorithmParameters>(params);
    283280                break;
     281            default:
     282                throwNotSupportedError(state, scope);
     283                return nullptr;
     284            }
     285            break;
     286        case Operations::GetKeyLength:
     287            switch (*identifier) {
     288            case CryptoAlgorithmIdentifier::AES_CTR:
     289            case CryptoAlgorithmIdentifier::AES_CBC:
     290            case CryptoAlgorithmIdentifier::AES_CMAC:
     291            case CryptoAlgorithmIdentifier::AES_GCM:
     292            case CryptoAlgorithmIdentifier::AES_CFB:
     293            case CryptoAlgorithmIdentifier::AES_KW: {
     294                auto params = convertDictionary<CryptoAlgorithmAesKeyParams>(state, value);
     295                RETURN_IF_EXCEPTION(scope, nullptr);
     296                result = std::make_unique<CryptoAlgorithmAesKeyParams>(params);
     297                break;
     298            }
     299            case CryptoAlgorithmIdentifier::HMAC: {
     300                auto params = convertDictionary<CryptoAlgorithmHmacKeyParams>(state, value);
     301                RETURN_IF_EXCEPTION(scope, nullptr);
     302                params.hashIdentifier = toHashIdentifier(state, params.hash);
     303                RETURN_IF_EXCEPTION(scope, nullptr);
     304                result = std::make_unique<CryptoAlgorithmHmacKeyParams>(params);
     305                break;
     306            }
    284307            default:
    285308                throwNotSupportedError(state, scope);
     
    488511    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& cipherText) mutable {
    489512        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), cipherText.data(), cipherText.size());
    490         return;
    491513    };
    492514    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     
    536558    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& plainText) mutable {
    537559        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), plainText.data(), plainText.size());
    538         return;
    539560    };
    540561    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     
    584605    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& signature) mutable {
    585606        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), signature.data(), signature.size());
    586         return;
    587607    };
    588608    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     
    635655    auto callback = [capturedPromise = promise.copyRef()](bool result) mutable {
    636656        capturedPromise->resolve<IDLBoolean>(result);
    637         return;
    638657    };
    639658    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     
    670689    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& digest) mutable {
    671690        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), digest.data(), digest.size());
    672         return;
    673691    };
    674692    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     
    744762    }
    745763
    746     auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::DeriveKey);
    747     RETURN_IF_EXCEPTION(scope, void());
    748 
    749     // We should always return a NOT_SUPPORTED_ERR since we currently don't support any algorithms that has deriveKey operation.
    750     ASSERT_NOT_REACHED();
     764    auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::DeriveBits);
     765    RETURN_IF_EXCEPTION(scope, void());
     766
     767    auto baseKey = toCryptoKey(state, state.uncheckedArgument(1));
     768    RETURN_IF_EXCEPTION(scope, void());
     769
     770    auto importParams = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(2), Operations::ImportKey);
     771    RETURN_IF_EXCEPTION(scope, void());
     772
     773    auto getLengthParams = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(2), Operations::GetKeyLength);
     774    RETURN_IF_EXCEPTION(scope, void());
     775
     776    auto extractable = state.uncheckedArgument(3).toBoolean(&state);
     777    RETURN_IF_EXCEPTION(scope, void());
     778
     779    auto keyUsages = cryptoKeyUsageBitmapFromJSValue(state, state.uncheckedArgument(4));
     780    RETURN_IF_EXCEPTION(scope, void());
     781
     782    if (params->identifier != baseKey->algorithmIdentifier()) {
     783        promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier"));
     784        return;
     785    }
     786
     787    if (!baseKey->allows(CryptoKeyUsageDeriveKey)) {
     788        promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support CryptoKey derivation"));
     789        return;
     790    }
     791
     792    auto getLengthAlgorithm = CryptoAlgorithmRegistry::singleton().create(getLengthParams->identifier);
     793    if (UNLIKELY(!getLengthAlgorithm)) {
     794        throwNotSupportedError(state, scope);
     795        return;
     796    }
     797    auto result = getLengthAlgorithm->getKeyLength(*getLengthParams);
     798    if (result.hasException()) {
     799        promise->reject(result.releaseException().code(), ASCIILiteral("Cannot get key length from derivedKeyType"));
     800        return;
     801    }
     802    size_t length = result.releaseReturnValue();
     803
     804    auto importAlgorithm = CryptoAlgorithmRegistry::singleton().create(importParams->identifier);
     805    if (UNLIKELY(!importAlgorithm)) {
     806        throwNotSupportedError(state, scope);
     807        return;
     808    }
     809
     810    auto algorithm = CryptoAlgorithmRegistry::singleton().create(params->identifier);
     811    if (UNLIKELY(!algorithm)) {
     812        throwNotSupportedError(state, scope);
     813        return;
     814    }
     815
     816    auto callback = [promise = promise.copyRef(), importAlgorithm, importParams = WTFMove(importParams), extractable, keyUsages](const Vector<uint8_t>& derivedKey) mutable {
     817        // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169395
     818        KeyData data = derivedKey;
     819        auto callback = [capturedPromise = promise.copyRef()](CryptoKey& key) mutable {
     820            if ((key.type() == CryptoKeyType::Private || key.type() == CryptoKeyType::Secret) && !key.usagesBitmap()) {
     821                rejectWithException(WTFMove(capturedPromise), SYNTAX_ERR);
     822                return;
     823            }
     824            capturedPromise->resolve<IDLInterface<CryptoKey>>(key);
     825        };
     826        auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     827            rejectWithException(WTFMove(capturedPromise), ec);
     828        };
     829
     830        importAlgorithm->importKey(SubtleCrypto::KeyFormat::Raw, WTFMove(data), WTFMove(importParams), extractable, keyUsages, WTFMove(callback), WTFMove(exceptionCallback));
     831    };
     832    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
     833        rejectWithException(WTFMove(capturedPromise), ec);
     834    };
     835
     836    auto subtle = jsDynamicDowncast<JSSubtleCrypto*>(vm, state.thisValue());
     837    ASSERT(subtle);
     838    algorithm->deriveBits(WTFMove(params), baseKey.releaseNonNull(), length, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
    751839}
    752840
     
    788876    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& derivedKey) mutable {
    789877        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), derivedKey.data(), derivedKey.size());
    790         return;
    791878    };
    792879    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp

    r213624 r213628  
    6363}
    6464
    65 void CryptoAlgorithm::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, unsigned long, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
     65void CryptoAlgorithm::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
    6666{
    6767    exceptionCallback(NOT_SUPPORTED_ERR);
     
    8686{
    8787    exceptionCallback(NOT_SUPPORTED_ERR);
     88}
     89
     90ExceptionOr<size_t> CryptoAlgorithm::getKeyLength(const CryptoAlgorithmParameters&)
     91{
     92    return Exception { NOT_SUPPORTED_ERR };
    8893}
    8994
     
    123128}
    124129
    125 ExceptionOr<void> CryptoAlgorithm::deriveBits(const CryptoAlgorithmParametersDeprecated&, const CryptoKey&, unsigned long, VectorCallback&&, VoidCallback&&)
     130ExceptionOr<void> CryptoAlgorithm::deriveBits(const CryptoAlgorithmParametersDeprecated&, const CryptoKey&, size_t, VectorCallback&&, VoidCallback&&)
    126131{
    127132    return Exception { NOT_SUPPORTED_ERR };
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.h

    r213624 r213628  
    6262    using KeyCallback = WTF::Function<void(CryptoKey&)>;
    6363    using KeyOrKeyPairCallback = WTF::Function<void(KeyOrKeyPair&&)>;
     64    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169395
    6465    using VectorCallback = WTF::Function<void(const Vector<uint8_t>&)>;
    6566    using VoidCallback = WTF::Function<void()>;
     
    7374    virtual void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    7475    virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
    75     virtual void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, unsigned long length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     76    virtual void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    7677    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169262
    7778    virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
     
    7980    virtual void wrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
    8081    virtual void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
     82    virtual ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
    8183
    8284    // The following will be deprecated.
     
    8890    virtual ExceptionOr<void> generateKey(const CryptoAlgorithmParametersDeprecated&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, VoidCallback&& failureCallback, ScriptExecutionContext&);
    8991    virtual ExceptionOr<void> deriveKey(const CryptoAlgorithmParametersDeprecated&, const CryptoKey& baseKey, CryptoAlgorithm* derivedKeyType, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, VoidCallback&& failureCallback);
    90     virtual ExceptionOr<void> deriveBits(const CryptoAlgorithmParametersDeprecated&, const CryptoKey& baseKey, unsigned long length, VectorCallback&&, VoidCallback&& failureCallback);
     92    virtual ExceptionOr<void> deriveBits(const CryptoAlgorithmParametersDeprecated&, const CryptoKey& baseKey, size_t length, VectorCallback&&, VoidCallback&& failureCallback);
    9193    virtual ExceptionOr<void> importKey(const CryptoAlgorithmParametersDeprecated&, const CryptoKeyData&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, VoidCallback&& failureCallback);
    9294
  • trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h

    r213624 r213628  
    4040        AesCbcCfbParams,
    4141        AesGcmParams,
    42         AesKeyGenParams,
     42        AesKeyParams,
    4343        EcKeyParams,
    4444        EcdhKeyDeriveParams,
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp

    r212736 r213628  
    3131#include "CryptoAlgorithmAesCbcCfbParams.h"
    3232#include "CryptoAlgorithmAesCbcParamsDeprecated.h"
    33 #include "CryptoAlgorithmAesKeyGenParams.h"
    3433#include "CryptoAlgorithmAesKeyGenParamsDeprecated.h"
     34#include "CryptoAlgorithmAesKeyParams.h"
    3535#include "CryptoKeyAES.h"
    3636#include "CryptoKeyDataOctetSequence.h"
     
    9191void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    9292{
    93     const auto& aesParameters = downcast<CryptoAlgorithmAesKeyGenParams>(parameters);
     93    const auto& aesParameters = downcast<CryptoAlgorithmAesKeyParams>(parameters);
    9494
    9595    if (usagesAreInvalidForCryptoAlgorithmAES_CBC(usages)) {
     
    187187}
    188188
     189ExceptionOr<size_t> CryptoAlgorithmAES_CBC::getKeyLength(const CryptoAlgorithmParameters& parameters)
     190{
     191    return CryptoKeyAES::getKeyLength(parameters);
     192}
     193
    189194ExceptionOr<void> CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParametersDeprecated& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
    190195{
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h

    r209077 r213628  
    5050    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5151    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     52    ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
    5253
    5354    ExceptionOr<void> encrypt(const CryptoAlgorithmParametersDeprecated&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CFB.cpp

    r212736 r213628  
    3030
    3131#include "CryptoAlgorithmAesCbcCfbParams.h"
    32 #include "CryptoAlgorithmAesKeyGenParams.h"
     32#include "CryptoAlgorithmAesKeyParams.h"
    3333#include "CryptoKeyAES.h"
    3434#include "ExceptionCode.h"
     
    8080void CryptoAlgorithmAES_CFB::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    8181{
    82     const auto& aesParameters = downcast<CryptoAlgorithmAesKeyGenParams>(parameters);
     82    const auto& aesParameters = downcast<CryptoAlgorithmAesKeyParams>(parameters);
    8383
    8484    if (usagesAreInvalidForCryptoAlgorithmAES_CFB(usages)) {
     
    176176}
    177177
     178ExceptionOr<size_t> CryptoAlgorithmAES_CFB::getKeyLength(const CryptoAlgorithmParameters& parameters)
     179{
     180    return CryptoKeyAES::getKeyLength(parameters);
     181}
     182
    178183}
    179184
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CFB.h

    r212736 r213628  
    4949    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5050    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     51    ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
    5152
    5253    void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp

    r213345 r213628  
    3030
    3131#include "CryptoAlgorithmAesGcmParams.h"
    32 #include "CryptoAlgorithmAesKeyGenParams.h"
     32#include "CryptoAlgorithmAesKeyParams.h"
    3333#include "CryptoKeyAES.h"
    3434#include "ExceptionCode.h"
     
    129129void CryptoAlgorithmAES_GCM::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
    130130{
    131     const auto& aesParameters = downcast<CryptoAlgorithmAesKeyGenParams>(parameters);
     131    const auto& aesParameters = downcast<CryptoAlgorithmAesKeyParams>(parameters);
    132132
    133133    if (usagesAreInvalidForCryptoAlgorithmAES_GCM(usages)) {
     
    225225}
    226226
     227ExceptionOr<size_t> CryptoAlgorithmAES_GCM::getKeyLength(const CryptoAlgorithmParameters& parameters)
     228{
     229    return CryptoKeyAES::getKeyLength(parameters);
     230}
     231
    227232}
    228233
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.h

    r213345 r213628  
    4949    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5050    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     51    ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
    5152
    5253    void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp

    r212465 r213628  
    2929#if ENABLE(SUBTLE_CRYPTO)
    3030
    31 #include "CryptoAlgorithmAesKeyGenParams.h"
    3231#include "CryptoAlgorithmAesKeyGenParamsDeprecated.h"
     32#include "CryptoAlgorithmAesKeyParams.h"
    3333#include "CryptoKeyAES.h"
    3434#include "CryptoKeyDataOctetSequence.h"
     
    7272    }
    7373
    74     auto result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_KW, downcast<CryptoAlgorithmAesKeyGenParams>(parameters).length, extractable, usages);
     74    auto result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_KW, downcast<CryptoAlgorithmAesKeyParams>(parameters).length, extractable, usages);
    7575    if (!result) {
    7676        exceptionCallback(OperationError);
     
    174174}
    175175
     176ExceptionOr<size_t> CryptoAlgorithmAES_KW::getKeyLength(const CryptoAlgorithmParameters& parameters)
     177{
     178    return CryptoKeyAES::getKeyLength(parameters);
     179}
     180
    176181ExceptionOr<void> CryptoAlgorithmAES_KW::encryptForWrapKey(const CryptoAlgorithmParametersDeprecated&, const CryptoKey& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
    177182{
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.h

    r209200 r213628  
    4949    void wrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&) final;
    5050    void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&) final;
     51    ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
    5152
    5253    ExceptionOr<void> encryptForWrapKey(const CryptoAlgorithmParametersDeprecated&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp

    r213624 r213628  
    6767}
    6868
    69 void CryptoAlgorithmECDH::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, unsigned long length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     69void CryptoAlgorithmECDH::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
    7070{
    7171    // We only accept length that is a multiple of 8.
     
    9898    }
    9999
    100     auto unifiedCallback = [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](std::optional<Vector<uint8_t>>&& derivedKey, unsigned long length) mutable {
     100    auto unifiedCallback = [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](std::optional<Vector<uint8_t>>&& derivedKey, size_t length) mutable {
    101101        if (!derivedKey) {
    102102            exceptionCallback(OperationError);
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h

    r213624 r213628  
    4343
    4444    void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
    45     void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, unsigned long length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     45    void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
    4646    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    4747    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
    4848
    49     using Callback = Function<void(std::optional<Vector<uint8_t>>&&, unsigned long)>;
    50     void platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, unsigned long length, Callback&&, ScriptExecutionContext&, WorkQueue&);
     49    using Callback = Function<void(std::optional<Vector<uint8_t>>&&, size_t)>;
     50    void platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, size_t length, Callback&&, ScriptExecutionContext&, WorkQueue&);
    5151};
    5252
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp

    r212465 r213628  
    198198}
    199199
     200ExceptionOr<size_t> CryptoAlgorithmHMAC::getKeyLength(const CryptoAlgorithmParameters& parameters)
     201{
     202    return CryptoKeyHMAC::getKeyLength(parameters);
     203}
     204
    200205ExceptionOr<void> CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParametersDeprecated& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
    201206{
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h

    r209150 r213628  
    5050    void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
    5151    void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     52    ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
    5253
    5354    // The following will be deprecated.
  • trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp

    r212465 r213628  
    2929#if ENABLE(SUBTLE_CRYPTO)
    3030
     31#include "CryptoAlgorithmAesKeyParams.h"
    3132#include "CryptoAlgorithmRegistry.h"
    3233#include "CryptoKeyDataOctetSequence.h"
     34#include "ExceptionCode.h"
     35#include "ExceptionOr.h"
    3336#include "JsonWebKey.h"
    3437#include <wtf/text/Base64.h>
     
    115118}
    116119
     120ExceptionOr<size_t> CryptoKeyAES::getKeyLength(const CryptoAlgorithmParameters& parameters)
     121{
     122    auto& aesParameters = downcast<CryptoAlgorithmAesKeyParams>(parameters);
     123    if (!lengthIsValid(aesParameters.length))
     124        return Exception { OperationError };
     125    return aesParameters.length;
     126}
     127
    117128std::unique_ptr<KeyAlgorithm> CryptoKeyAES::buildAlgorithm() const
    118129{
  • trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h

    r212465 r213628  
    2828#include "CryptoAlgorithmIdentifier.h"
    2929#include "CryptoKey.h"
     30#include "ExceptionOr.h"
    3031#include <wtf/Function.h>
    3132#include <wtf/Vector.h>
     
    3435
    3536namespace WebCore {
     37
     38class CryptoAlgorithmParameters;
    3639
    3740struct JsonWebKey;
     
    7780    JsonWebKey exportJwk() const;
    7881
     82    static ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
     83
    7984private:
    8085    CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsageBitmap);
  • trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp

    r213560 r213628  
    3232#include "CryptoAlgorithmRegistry.h"
    3333#include "CryptoKeyDataOctetSequence.h"
     34#include "ExceptionCode.h"
     35#include "ExceptionOr.h"
    3436#include "JsonWebKey.h"
    3537#include <wtf/text/Base64.h>
     
    3739
    3840namespace WebCore {
     41
     42static size_t getKeyLengthFromHash(CryptoAlgorithmIdentifier hash)
     43{
     44    switch (hash) {
     45    case CryptoAlgorithmIdentifier::SHA_1:
     46    case CryptoAlgorithmIdentifier::SHA_224:
     47    case CryptoAlgorithmIdentifier::SHA_256:
     48        return 512;
     49    case CryptoAlgorithmIdentifier::SHA_384:
     50    case CryptoAlgorithmIdentifier::SHA_512:
     51        return 1024;
     52    default:
     53        ASSERT_NOT_REACHED();
     54        return 0;
     55    }
     56}
    3957
    4058CryptoKeyHMAC::CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap usage)
     
    5977{
    6078    if (!lengthBits) {
    61         switch (hash) {
    62         case CryptoAlgorithmIdentifier::SHA_1:
    63         case CryptoAlgorithmIdentifier::SHA_224:
    64         case CryptoAlgorithmIdentifier::SHA_256:
    65             lengthBits = 512;
    66             break;
    67         case CryptoAlgorithmIdentifier::SHA_384:
    68         case CryptoAlgorithmIdentifier::SHA_512:
    69             lengthBits = 1024;
    70             break;
    71         default:
     79        lengthBits = getKeyLengthFromHash(hash);
     80        if (!lengthBits)
    7281            return nullptr;
    73         }
    7482    }
    7583    // CommonHMAC only supports key length that is a multiple of 8. Therefore, here we are a little bit different
     
    125133}
    126134
     135ExceptionOr<size_t> CryptoKeyHMAC::getKeyLength(const CryptoAlgorithmParameters& parameters)
     136{
     137    auto& aesParameters = downcast<CryptoAlgorithmHmacKeyParams>(parameters);
     138
     139    size_t result = aesParameters.length ? *(aesParameters.length) : getKeyLengthFromHash(aesParameters.hashIdentifier);
     140    if (result)
     141        return result;
     142
     143    return Exception { TypeError };
     144}
     145
    127146std::unique_ptr<KeyAlgorithm> CryptoKeyHMAC::buildAlgorithm() const
    128147{
  • trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h

    r212465 r213628  
    2929
    3030#include "CryptoKey.h"
     31#include "ExceptionOr.h"
    3132#include <wtf/Function.h>
    3233#include <wtf/Vector.h>
    3334
    3435namespace WebCore {
     36
     37class CryptoAlgorithmParameters;
    3538
    3639struct JsonWebKey;
     
    7578    CryptoAlgorithmIdentifier hashAlgorithmIdentifier() const { return m_hash; }
    7679
     80    static ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
     81
    7782private:
    7883    CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap);
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDHMac.cpp

    r213624 r213628  
    3535namespace WebCore {
    3636
    37 void CryptoAlgorithmECDH::platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, unsigned long length, Callback&& callback, ScriptExecutionContext& context, WorkQueue& workQueue)
     37void CryptoAlgorithmECDH::platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, size_t length, Callback&& callback, ScriptExecutionContext& context, WorkQueue& workQueue)
    3838{
    3939    context.ref();
  • trunk/Source/WebCore/crypto/parameters/AesKeyParams.idl

    r213627 r213628  
    2424 */
    2525
     26// This is a unified dictionary for AesDerivedKeyParams and AesKeyGenParams.
     27// https://www.w3.org/TR/WebCryptoAPI/#aes-derivedkey-params, and
     28// https://www.w3.org/TR/WebCryptoAPI/#aes-keygen-params
    2629[
    2730    Conditional=SUBTLE_CRYPTO,
    28     ImplementedAs=CryptoAlgorithmAesKeyGenParams
    29 ] dictionary AesKeyGenParams : CryptoAlgorithmParameters {
     31    ImplementedAs=CryptoAlgorithmAesKeyParams
     32] dictionary AesKeyParams : CryptoAlgorithmParameters {
    3033    // The length, in bits, of the key.
    3134    [EnforceRange] required unsigned short length;
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyParams.h

    r213627 r213628  
    3232namespace WebCore {
    3333
    34 class CryptoAlgorithmAesKeyGenParams final : public CryptoAlgorithmParameters {
     34class CryptoAlgorithmAesKeyParams final : public CryptoAlgorithmParameters {
    3535public:
    3636    unsigned short length;
    3737
    38     Class parametersClass() const final { return Class::AesKeyGenParams; }
     38    Class parametersClass() const final { return Class::AesKeyParams; }
    3939};
    4040
    4141} // namespace WebCore
    4242
    43 SPECIALIZE_TYPE_TRAITS_CRYPTO_ALGORITHM_PARAMETERS(AesKeyGenParams)
     43SPECIALIZE_TYPE_TRAITS_CRYPTO_ALGORITHM_PARAMETERS(AesKeyParams)
    4444
    4545#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParams.h

    r208985 r213628  
    3838    JSC::JSValue hash;
    3939    CryptoAlgorithmIdentifier hashIdentifier;
    40     std::optional<unsigned long> length;
     40    std::optional<size_t> length;
    4141
    4242    Class parametersClass() const final { return Class::HmacKeyParams; }
  • trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h

    r207809 r213628  
    3636class CryptoAlgorithmRsaKeyGenParams : public CryptoAlgorithmParameters {
    3737public:
    38     unsigned long modulusLength;
     38    size_t modulusLength;
    3939    RefPtr<Uint8Array> publicExponent;
    4040
Note: See TracChangeset for help on using the changeset viewer.