mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Expose support for P-521 in ECDH and ECDSA
Replace all TODOs and FIXMEs requiring P-521 support with actual code paths that make use of it. Gets a few tests by simply not failing early.
This commit is contained in:
parent
c3aa8af514
commit
70db7772b8
Notes:
github-actions[bot]
2024-12-14 00:53:16 +00:00
Author: https://github.com/devgianlu Commit: https://github.com/LadybirdBrowser/ladybird/commit/70db7772b89 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2902 Reviewed-by: https://github.com/alimpfard
3 changed files with 64 additions and 67 deletions
|
@ -3,6 +3,7 @@
|
|||
* Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
|
||||
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2024, Altomani Gianluca <altomanigianluca@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -2265,17 +2266,16 @@ WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> ECDSA::
|
|||
// 2. If the namedCurve member of normalizedAlgorithm is "P-256", "P-384" or "P-521":
|
||||
// Generate an Elliptic Curve key pair, as defined in [RFC6090]
|
||||
// with domain parameters for the curve identified by the namedCurve member of normalizedAlgorithm.
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (normalized_algorithm.named_curve.is_one_of("P-256"sv, "P-384"sv, "P-521"sv)) {
|
||||
if (normalized_algorithm.named_curve == "P-256")
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
|
||||
if (normalized_algorithm.named_curve == "P-384")
|
||||
else if (normalized_algorithm.named_curve == "P-384")
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
|
||||
// FIXME: Support P-521
|
||||
if (normalized_algorithm.named_curve == "P-521")
|
||||
return WebIDL::NotSupportedError::create(m_realm, "'P-521' is not supported yet"_string);
|
||||
else if (normalized_algorithm.named_curve == "P-521")
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
// If the namedCurve member of normalizedAlgorithm is a value specified in an applicable specification:
|
||||
// Perform the ECDSA generation steps specified in that specification,
|
||||
|
@ -2399,17 +2399,16 @@ WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> ECDSA::sign(AlgorithmParams const&
|
|||
// 6. If the namedCurve attribute of the [[algorithm]] internal slot of key is "P-256", "P-384" or "P-521":
|
||||
if (named_curve.is_one_of("P-256"sv, "P-384"sv, "P-521"sv)) {
|
||||
size_t coord_size;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (named_curve == "P-256") {
|
||||
coord_size = 32;
|
||||
coord_size = 256 / 8;
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
} else if (named_curve == "P-384") {
|
||||
coord_size = 48;
|
||||
coord_size = 384 / 8;
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
} else if (named_curve == "P-521") {
|
||||
// FIXME: Support P-521
|
||||
coord_size = 66;
|
||||
return WebIDL::NotSupportedError::create(m_realm, "'P-521' is not supported yet"_string);
|
||||
coord_size = ceil_div(521, 8);
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -2492,17 +2491,16 @@ WebIDL::ExceptionOr<JS::Value> ECDSA::verify(AlgorithmParams const& params, GC::
|
|||
|
||||
auto result = false;
|
||||
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (named_curve.is_one_of("P-256"sv, "P-384"sv, "P-521"sv)) {
|
||||
if (named_curve == "P-256")
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
|
||||
if (named_curve == "P-384")
|
||||
else if (named_curve == "P-384")
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
|
||||
// FIXME: Support P-521
|
||||
if (named_curve == "P-521")
|
||||
return WebIDL::NotSupportedError::create(m_realm, "'P-521' is not supported yet"_string);
|
||||
else if (named_curve == "P-521")
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
// Perform the ECDSA verifying process, as specified in [RFC6090], Section 5.3,
|
||||
// with M as the received message, signature as the received signature
|
||||
|
@ -2810,11 +2808,11 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> ECDSA::import_key(AlgorithmParams const&
|
|||
|
||||
size_t coord_size;
|
||||
if (named_curve == "P-256"sv)
|
||||
coord_size = 32;
|
||||
coord_size = 256 / 8;
|
||||
else if (named_curve == "P-384"sv)
|
||||
coord_size = 48;
|
||||
coord_size = 384 / 8;
|
||||
else if (named_curve == "P-521"sv)
|
||||
coord_size = 66;
|
||||
coord_size = ceil_div(521, 8);
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
|
@ -3145,16 +3143,16 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> ECDSA::export_key(Bindings::KeyFormat f
|
|||
},
|
||||
[&](::Crypto::PK::ECPrivateKey<> const& private_key) -> ErrorOr<void> {
|
||||
size_t coord_size;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (algorithm.named_curve() == "P-256"sv) {
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
coord_size = 256 / 8;
|
||||
coord_size = 32;
|
||||
} else if (algorithm.named_curve() == "P-384"sv) {
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
coord_size = 384 / 8;
|
||||
coord_size = 48;
|
||||
} else if (algorithm.named_curve() == "P-521"sv) {
|
||||
// FIXME: Support P-521
|
||||
return {};
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
coord_size = 66;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -3284,17 +3282,16 @@ WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> ECDH::g
|
|||
// 2. If the namedCurve member of normalizedAlgorithm is "P-256", "P-384" or "P-521":
|
||||
// Generate an Elliptic Curve key pair, as defined in [RFC6090]
|
||||
// with domain parameters for the curve identified by the namedCurve member of normalizedAlgorithm.
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (normalized_algorithm.named_curve.is_one_of("P-256"sv, "P-384"sv, "P-521"sv)) {
|
||||
if (normalized_algorithm.named_curve == "P-256")
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
|
||||
if (normalized_algorithm.named_curve == "P-384")
|
||||
else if (normalized_algorithm.named_curve == "P-384")
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
|
||||
// FIXME: Support P-521
|
||||
if (normalized_algorithm.named_curve == "P-521")
|
||||
return WebIDL::NotSupportedError::create(m_realm, "'P-521' is not supported yet"_string);
|
||||
else if (normalized_algorithm.named_curve == "P-521")
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
// If the namedCurve member of normalizedAlgorithm is a value specified in an applicable specification
|
||||
// that specifies the use of that value with ECDH:
|
||||
|
@ -3415,15 +3412,15 @@ WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> ECDH::derive_bits(AlgorithmParams
|
|||
auto private_key_data = key->handle().get<::Crypto::PK::ECPrivateKey<>>();
|
||||
auto public_key_data = public_key->handle().get<::Crypto::PK::ECPublicKey<>>();
|
||||
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
if (internal_algorithm.named_curve() == "P-256"sv) {
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (internal_algorithm.named_curve() == "P-256"sv)
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
} else if (internal_algorithm.named_curve() == "P-384"sv) {
|
||||
else if (internal_algorithm.named_curve() == "P-384"sv)
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
} else if (internal_algorithm.named_curve() == "P-521"sv) {
|
||||
// TODO: Support P-521
|
||||
return WebIDL::NotSupportedError::create(m_realm, "'P-521' is not supported yet"_string);
|
||||
}
|
||||
else if (internal_algorithm.named_curve() == "P-521"sv)
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto maybe_secret = curve.visit(
|
||||
[](Empty const&) -> ErrorOr<::Crypto::Curves::SECPxxxr1Point> { return Error::from_string_literal("noop error"); },
|
||||
|
@ -3713,11 +3710,11 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> ECDH::import_key(AlgorithmParams const&
|
|||
if (named_curve.is_one_of("P-256"sv, "P-384"sv, "P-521"sv)) {
|
||||
size_t coord_size;
|
||||
if (named_curve == "P-256"sv)
|
||||
coord_size = 32;
|
||||
coord_size = 256 / 8;
|
||||
else if (named_curve == "P-384"sv)
|
||||
coord_size = 48;
|
||||
coord_size = 384 / 8;
|
||||
else if (named_curve == "P-521"sv)
|
||||
coord_size = 66;
|
||||
coord_size = ceil_div(521, 8);
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
|
@ -4039,16 +4036,16 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> ECDH::export_key(Bindings::KeyFormat fo
|
|||
},
|
||||
[&](::Crypto::PK::ECPrivateKey<> const& private_key) -> ErrorOr<void> {
|
||||
size_t coord_size;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1> curve;
|
||||
Variant<Empty, ::Crypto::Curves::SECP256r1, ::Crypto::Curves::SECP384r1, ::Crypto::Curves::SECP521r1> curve;
|
||||
if (algorithm.named_curve() == "P-256"sv) {
|
||||
curve = ::Crypto::Curves::SECP256r1 {};
|
||||
coord_size = 256 / 8;
|
||||
coord_size = 32;
|
||||
} else if (algorithm.named_curve() == "P-384"sv) {
|
||||
curve = ::Crypto::Curves::SECP384r1 {};
|
||||
coord_size = 384 / 8;
|
||||
coord_size = 48;
|
||||
} else if (algorithm.named_curve() == "P-521"sv) {
|
||||
// FIXME: Support P-521
|
||||
return {};
|
||||
curve = ::Crypto::Curves::SECP521r1 {};
|
||||
coord_size = 66;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ Harness status: OK
|
|||
|
||||
Found 40 tests
|
||||
|
||||
30 Pass
|
||||
10 Fail
|
||||
31 Pass
|
||||
9 Fail
|
||||
Pass setup - define tests
|
||||
Fail P-521 good parameters
|
||||
Fail P-521 mixed case parameters
|
||||
|
@ -17,7 +17,7 @@ Pass P-521 no deriveBits usage for base key
|
|||
Pass P-521 base key is not a private key
|
||||
Pass P-521 public property value is a private key
|
||||
Pass P-521 public property value is a secret key
|
||||
Fail P-521 asking for too many bits
|
||||
Pass P-521 asking for too many bits
|
||||
Pass P-256 good parameters
|
||||
Pass P-256 mixed case parameters
|
||||
Pass P-256 short result
|
||||
|
|
|
@ -2,8 +2,8 @@ Harness status: OK
|
|||
|
||||
Found 253 tests
|
||||
|
||||
193 Pass
|
||||
60 Fail
|
||||
205 Pass
|
||||
48 Fail
|
||||
Pass setup
|
||||
Pass ECDSA P-256 with SHA-1 verification
|
||||
Pass ECDSA P-256 with SHA-256 verification
|
||||
|
@ -233,27 +233,27 @@ Fail ECDSA P-521 with SHA-1 - The signature was truncated by 1 byte verification
|
|||
Fail ECDSA P-521 with SHA-1 - The signature was made using SHA-1, however verification is being done using SHA-256 verification
|
||||
Fail ECDSA P-521 with SHA-1 - The signature was made using SHA-1, however verification is being done using SHA-384 verification
|
||||
Fail ECDSA P-521 with SHA-1 - The signature was made using SHA-1, however verification is being done using SHA-512 verification
|
||||
Fail ECDSA P-521 with SHA-1 - Signature has excess padding verification
|
||||
Fail ECDSA P-521 with SHA-1 - The signature is empty verification
|
||||
Fail ECDSA P-521 with SHA-1 - The signature is all zeroes verification
|
||||
Pass ECDSA P-521 with SHA-1 - Signature has excess padding verification
|
||||
Pass ECDSA P-521 with SHA-1 - The signature is empty verification
|
||||
Pass ECDSA P-521 with SHA-1 - The signature is all zeroes verification
|
||||
Fail ECDSA P-521 with SHA-256 - The signature was truncated by 1 byte verification
|
||||
Fail ECDSA P-521 with SHA-256 - The signature was made using SHA-256, however verification is being done using SHA-1 verification
|
||||
Fail ECDSA P-521 with SHA-256 - The signature was made using SHA-256, however verification is being done using SHA-384 verification
|
||||
Fail ECDSA P-521 with SHA-256 - The signature was made using SHA-256, however verification is being done using SHA-512 verification
|
||||
Fail ECDSA P-521 with SHA-256 - Signature has excess padding verification
|
||||
Fail ECDSA P-521 with SHA-256 - The signature is empty verification
|
||||
Fail ECDSA P-521 with SHA-256 - The signature is all zeroes verification
|
||||
Pass ECDSA P-521 with SHA-256 - Signature has excess padding verification
|
||||
Pass ECDSA P-521 with SHA-256 - The signature is empty verification
|
||||
Pass ECDSA P-521 with SHA-256 - The signature is all zeroes verification
|
||||
Fail ECDSA P-521 with SHA-384 - The signature was truncated by 1 byte verification
|
||||
Fail ECDSA P-521 with SHA-384 - The signature was made using SHA-384, however verification is being done using SHA-1 verification
|
||||
Fail ECDSA P-521 with SHA-384 - The signature was made using SHA-384, however verification is being done using SHA-256 verification
|
||||
Fail ECDSA P-521 with SHA-384 - The signature was made using SHA-384, however verification is being done using SHA-512 verification
|
||||
Fail ECDSA P-521 with SHA-384 - Signature has excess padding verification
|
||||
Fail ECDSA P-521 with SHA-384 - The signature is empty verification
|
||||
Fail ECDSA P-521 with SHA-384 - The signature is all zeroes verification
|
||||
Pass ECDSA P-521 with SHA-384 - Signature has excess padding verification
|
||||
Pass ECDSA P-521 with SHA-384 - The signature is empty verification
|
||||
Pass ECDSA P-521 with SHA-384 - The signature is all zeroes verification
|
||||
Fail ECDSA P-521 with SHA-512 - The signature was truncated by 1 byte verification
|
||||
Fail ECDSA P-521 with SHA-512 - The signature was made using SHA-512, however verification is being done using SHA-1 verification
|
||||
Fail ECDSA P-521 with SHA-512 - The signature was made using SHA-512, however verification is being done using SHA-256 verification
|
||||
Fail ECDSA P-521 with SHA-512 - The signature was made using SHA-512, however verification is being done using SHA-384 verification
|
||||
Fail ECDSA P-521 with SHA-512 - Signature has excess padding verification
|
||||
Fail ECDSA P-521 with SHA-512 - The signature is empty verification
|
||||
Fail ECDSA P-521 with SHA-512 - The signature is all zeroes verification
|
||||
Pass ECDSA P-521 with SHA-512 - Signature has excess padding verification
|
||||
Pass ECDSA P-521 with SHA-512 - The signature is empty verification
|
||||
Pass ECDSA P-521 with SHA-512 - The signature is all zeroes verification
|
Loading…
Add table
Reference in a new issue