[GCrypt] Add support for P-521 EC curves
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Oct 2017 08:23:16 +0000 (08:23 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Oct 2017 08:23:16 +0000 (08:23 +0000)
commit3f7237e64244402575faf31b5526c8f6afadbc9d
tree7befa82a7c63e9f59a537a1e42fec3da06e77658
parent4d76ccd135b4e27c9707ba526bacb76ce184fc74
[GCrypt] Add support for P-521 EC curves
https://bugs.webkit.org/show_bug.cgi?id=175199

Reviewed by Jiewen Tan.

Source/WebCore:

Add support for 521-bit elliptic curves in the libgcrypt-based
implementation of WebCrypto API.

In the CryptoAlgorithmECDH implementation, the bit-size of the key is now
rounded up to the next byte boundary and passed to the helper
gcryptDerive() function. There the size in bytes is used to zero-pad the
derived key data. This is done to properly handle derivation results for
the P-521 curves, where the leading zero bit could get clipped, resulting
in a derived key that is only 65 byes in length when it is expected to be
66 bytes. Further cleanups are done in gcryptDerive() to use the mpiData()
function where possible.

In the CryptoAlgorithmECDSA implementation, the bit-size of the key is
again rounded up to the nearest byte boundary before being passed to the
helper gcryptSign() and gcryptVerify() functions. This again properly
enforces the requirement of 66 bytes to handle P-521 elliptic curves.

In the CryptoKeyEC implementation, NamedCurve::P521 cases in helper
functions operating on NamedCurve values are now implemented to return
appropriate values. platformSupportedCurve() now returns true for the
NamedCurve::P521 value. Zero-padding of the private key data is used
wherever it is necessary to avoid clipping any leading zero bit in the
P-521 EC key.

No new tests -- affected tests have their baselines updated.

* crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp:
(WebCore::gcryptDerive):
(WebCore::CryptoAlgorithmECDH::platformDeriveBits):
* crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp:
(WebCore::CryptoAlgorithmECDSA::platformSign):
(WebCore::CryptoAlgorithmECDSA::platformVerify):
* crypto/gcrypt/CryptoKeyECGCrypt.cpp:
(WebCore::curveName):
(WebCore::curveIdentifier):
(WebCore::curveSize):
(WebCore::curveUncompressedFieldElementSize):
(WebCore::CryptoKeyEC::platformSupportedCurve):
(WebCore::curveForIdentifier):
(WebCore::CryptoKeyEC::platformImportPkcs8):
(WebCore::CryptoKeyEC::platformAddFieldElements const):
(WebCore::CryptoKeyEC::platformExportPkcs8 const):

LayoutTests:

Add or update Web Crypto test baselines for the GTK+ and WPE ports
to reflect the added EC P-521 support.

* platform/gtk/crypto/subtle/ec-generate-key-malformed-parameters-expected.txt: Added.
* platform/gtk/crypto/subtle/ecdh-derive-bits-length-limits-expected.txt: Added.
* platform/gtk/crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_keys.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_bits.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_keys.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures.worker-expected.txt:
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDH.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDSA.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes.worker-expected.txt:
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDH.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDSA.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures.https-expected.txt:
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDH.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDSA.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDH.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDSA.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/ec_importKey.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_ec_importKey.https-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/ecdsa.worker-expected.txt: Added.
* platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/test_ecdsa.https-expected.txt: Added.
* platform/wpe/crypto/subtle/ec-generate-key-malformed-parameters-expected.txt: Added.
* platform/wpe/crypto/subtle/ecdh-derive-bits-length-limits-expected.txt: Added.
* platform/wpe/crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_keys.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_bits.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_keys.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures.worker-expected.txt:
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDH.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDSA.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes.worker-expected.txt:
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDH.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDSA.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures.https-expected.txt:
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDH.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDSA.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDH.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDSA.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/ec_importKey.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_ec_importKey.https-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/ecdsa.worker-expected.txt: Added.
* platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/test_ecdsa.https-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224173 268f45cc-cd09-0410-ab3c-d52691b4dbfc
49 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/gtk/crypto/subtle/ec-generate-key-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/crypto/subtle/ecdh-derive-bits-length-limits-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_keys.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_bits.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_keys.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures.worker-expected.txt
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDH.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDSA.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes.worker-expected.txt
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDH.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDSA.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures.https-expected.txt
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDH.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDSA.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDH.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDSA.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/ec_importKey.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_ec_importKey.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/ecdsa.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/test_ecdsa.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/crypto/subtle/ec-generate-key-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/crypto/subtle/ecdh-derive-bits-length-limits-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_bits.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/ecdh_keys.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_bits.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_ecdh_keys.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures.worker-expected.txt
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDH.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDSA.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes.worker-expected.txt
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDH.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDSA.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures.https-expected.txt
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDH.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDSA.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDH.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDSA.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/ec_importKey.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_ec_importKey.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/ecdsa.worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/wpe/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/test_ecdsa.https-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoKeyECGCrypt.cpp