Skip to content

Commit bb112f5

Browse files
committed
LibWeb: Add Ed448 support in WebCryptoAPI
Add full support for Ed448 and import relevant tests.
1 parent f207eac commit bb112f5

File tree

15 files changed

+1521
-7
lines changed

15 files changed

+1521
-7
lines changed

Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp

Lines changed: 523 additions & 0 deletions
Large diffs are not rendered by default.

Libraries/LibWeb/Crypto/CryptoAlgorithms.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,24 @@ class ED25519 : public AlgorithmMethods {
544544
}
545545
};
546546

547+
class ED448 : public AlgorithmMethods {
548+
public:
549+
virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> sign(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
550+
virtual WebIDL::ExceptionOr<JS::Value> verify(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&, ByteBuffer const&) override;
551+
552+
virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
553+
virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
554+
virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
555+
556+
static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new ED448(realm)); }
557+
558+
private:
559+
explicit ED448(JS::Realm& realm)
560+
: AlgorithmMethods(realm)
561+
{
562+
}
563+
};
564+
547565
class X25519 : public AlgorithmMethods {
548566
public:
549567
virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, GC::Ref<CryptoKey>, Optional<u32>) override;
@@ -620,6 +638,20 @@ struct EcKeyImportParams : public AlgorithmParams {
620638
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
621639
};
622640

641+
// https://wicg.github.io/webcrypto-secure-curves/#dfn-Ed448Params
642+
struct Ed448Params : public AlgorithmParams {
643+
virtual ~Ed448Params() override;
644+
645+
Ed448Params(Optional<ByteBuffer>& context)
646+
: context(context)
647+
{
648+
}
649+
650+
Optional<ByteBuffer> context;
651+
652+
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
653+
};
654+
623655
ErrorOr<String> base64_url_uint_encode(::Crypto::UnsignedBigInteger);
624656
WebIDL::ExceptionOr<ByteBuffer> base64_url_bytes_decode(JS::Realm&, String const& base64_url_string);
625657
WebIDL::ExceptionOr<::Crypto::UnsignedBigInteger> base64_url_uint_decode(JS::Realm&, String const& base64_url_string);

Libraries/LibWeb/Crypto/SubtleCrypto.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,11 +1181,11 @@ SupportedAlgorithmsMap const& supported_algorithms()
11811181
define_an_algorithm<ED25519>("exportKey"_string, "Ed25519"_string);
11821182

11831183
// https://wicg.github.io/webcrypto-secure-curves/#ed448-registration
1184-
// FIXME: define_an_algorithm<ED448, Ed448Params>("sign"_string, "Ed448"_string);
1185-
// FIXME: define_an_algorithm<ED448, Ed448Params>("verify"_string, "Ed448"_string);
1186-
// FIXME: define_an_algorithm<ED448>("generateKey"_string, "Ed448"_string);
1187-
// FIXME: define_an_algorithm<ED448>("importKey"_string, "Ed448"_string);
1188-
// FIXME: define_an_algorithm<ED448>("exportKey"_string, "Ed448"_string);
1184+
define_an_algorithm<ED448, Ed448Params>("sign"_string, "Ed448"_string);
1185+
define_an_algorithm<ED448, Ed448Params>("verify"_string, "Ed448"_string);
1186+
define_an_algorithm<ED448>("generateKey"_string, "Ed448"_string);
1187+
define_an_algorithm<ED448>("importKey"_string, "Ed448"_string);
1188+
define_an_algorithm<ED448>("exportKey"_string, "Ed448"_string);
11891189

11901190
return internal_object;
11911191
}

Tests/LibWeb/Text/expected/wpt-import/WebCryptoAPI/generateKey/failures_Ed448.https.any.txt

Lines changed: 391 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Harness status: OK
2+
3+
Found 18 tests
4+
5+
18 Pass
6+
Pass Success: generateKey({name: ED448}, false, [sign])
7+
Pass Success: generateKey({name: ED448}, true, [sign])
8+
Pass Success: generateKey({name: ED448}, false, [verify, sign])
9+
Pass Success: generateKey({name: ED448}, true, [verify, sign])
10+
Pass Success: generateKey({name: ED448}, false, [sign, verify, sign, sign, verify])
11+
Pass Success: generateKey({name: ED448}, true, [sign, verify, sign, sign, verify])
12+
Pass Success: generateKey({name: ed448}, false, [sign])
13+
Pass Success: generateKey({name: ed448}, true, [sign])
14+
Pass Success: generateKey({name: ed448}, false, [verify, sign])
15+
Pass Success: generateKey({name: ed448}, true, [verify, sign])
16+
Pass Success: generateKey({name: ed448}, false, [sign, verify, sign, sign, verify])
17+
Pass Success: generateKey({name: ed448}, true, [sign, verify, sign, sign, verify])
18+
Pass Success: generateKey({name: Ed448}, false, [sign])
19+
Pass Success: generateKey({name: Ed448}, true, [sign])
20+
Pass Success: generateKey({name: Ed448}, false, [verify, sign])
21+
Pass Success: generateKey({name: Ed448}, true, [verify, sign])
22+
Pass Success: generateKey({name: Ed448}, false, [sign, verify, sign, sign, verify])
23+
Pass Success: generateKey({name: Ed448}, true, [sign, verify, sign, sign, verify])
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Harness status: OK
2+
3+
Found 13 tests
4+
5+
13 Pass
6+
Pass EdDSA Ed448 verification
7+
Pass EdDSA Ed448 verification with altered signature after call
8+
Pass EdDSA Ed448 with altered data after call
9+
Pass EdDSA Ed448 using privateKey to verify
10+
Pass EdDSA Ed448 using publicKey to sign
11+
Pass EdDSA Ed448 no verify usage
12+
Pass EdDSA Ed448 round trip
13+
Pass EdDSA Ed448 signing with wrong algorithm name
14+
Pass EdDSA Ed448 verifying with wrong algorithm name
15+
Pass EdDSA Ed448 verification failure due to altered signature
16+
Pass EdDSA Ed448 verification failure due to shortened signature
17+
Pass EdDSA Ed448 verification failure due to altered data
18+
Pass Sign and verify using generated Ed448 keys.

Tests/LibWeb/Text/expected/wpt-import/WebCryptoAPI/wrapKey_unwrapKey/wrapKey_unwrapKey.https.any.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Harness status: OK
22

3-
Found 281 tests
3+
Found 309 tests
44

5-
281 Pass
5+
309 Pass
66
Pass setup
77
Pass Can wrap and unwrap RSA-OAEP public key keys using spki and RSA-OAEP
88
Pass Can wrap and unwrap RSA-OAEP public key keys using jwk and RSA-OAEP
@@ -27,6 +27,13 @@ Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using pkcs8
2727
Pass Can wrap and unwrap Ed25519 private key keys using jwk and RSA-OAEP
2828
Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using jwk and RSA-OAEP
2929
Pass Can unwrap Ed25519 private key non-extractable keys using jwk and RSA-OAEP
30+
Pass Can wrap and unwrap Ed448 public key keys using spki and RSA-OAEP
31+
Pass Can wrap and unwrap Ed448 public key keys using jwk and RSA-OAEP
32+
Pass Can wrap and unwrap Ed448 private key keys using pkcs8 and RSA-OAEP
33+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using pkcs8 and RSA-OAEP
34+
Pass Can wrap and unwrap Ed448 private key keys using jwk and RSA-OAEP
35+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using jwk and RSA-OAEP
36+
Pass Can unwrap Ed448 private key non-extractable keys using jwk and RSA-OAEP
3037
Pass Can wrap and unwrap X25519 public key keys using spki and RSA-OAEP
3138
Pass Can wrap and unwrap X25519 public key keys using jwk and RSA-OAEP
3239
Pass Can wrap and unwrap X25519 private key keys using pkcs8 and RSA-OAEP
@@ -94,6 +101,13 @@ Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using pkcs8
94101
Pass Can wrap and unwrap Ed25519 private key keys using jwk and AES-CTR
95102
Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using jwk and AES-CTR
96103
Pass Can unwrap Ed25519 private key non-extractable keys using jwk and AES-CTR
104+
Pass Can wrap and unwrap Ed448 public key keys using spki and AES-CTR
105+
Pass Can wrap and unwrap Ed448 public key keys using jwk and AES-CTR
106+
Pass Can wrap and unwrap Ed448 private key keys using pkcs8 and AES-CTR
107+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using pkcs8 and AES-CTR
108+
Pass Can wrap and unwrap Ed448 private key keys using jwk and AES-CTR
109+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using jwk and AES-CTR
110+
Pass Can unwrap Ed448 private key non-extractable keys using jwk and AES-CTR
97111
Pass Can wrap and unwrap X25519 public key keys using spki and AES-CTR
98112
Pass Can wrap and unwrap X25519 public key keys using jwk and AES-CTR
99113
Pass Can wrap and unwrap X25519 private key keys using pkcs8 and AES-CTR
@@ -161,6 +175,13 @@ Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using pkcs8
161175
Pass Can wrap and unwrap Ed25519 private key keys using jwk and AES-CBC
162176
Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using jwk and AES-CBC
163177
Pass Can unwrap Ed25519 private key non-extractable keys using jwk and AES-CBC
178+
Pass Can wrap and unwrap Ed448 public key keys using spki and AES-CBC
179+
Pass Can wrap and unwrap Ed448 public key keys using jwk and AES-CBC
180+
Pass Can wrap and unwrap Ed448 private key keys using pkcs8 and AES-CBC
181+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using pkcs8 and AES-CBC
182+
Pass Can wrap and unwrap Ed448 private key keys using jwk and AES-CBC
183+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using jwk and AES-CBC
184+
Pass Can unwrap Ed448 private key non-extractable keys using jwk and AES-CBC
164185
Pass Can wrap and unwrap X25519 public key keys using spki and AES-CBC
165186
Pass Can wrap and unwrap X25519 public key keys using jwk and AES-CBC
166187
Pass Can wrap and unwrap X25519 private key keys using pkcs8 and AES-CBC
@@ -228,6 +249,13 @@ Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using pkcs8
228249
Pass Can wrap and unwrap Ed25519 private key keys using jwk and AES-GCM
229250
Pass Can wrap and unwrap Ed25519 private key keys as non-extractable using jwk and AES-GCM
230251
Pass Can unwrap Ed25519 private key non-extractable keys using jwk and AES-GCM
252+
Pass Can wrap and unwrap Ed448 public key keys using spki and AES-GCM
253+
Pass Can wrap and unwrap Ed448 public key keys using jwk and AES-GCM
254+
Pass Can wrap and unwrap Ed448 private key keys using pkcs8 and AES-GCM
255+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using pkcs8 and AES-GCM
256+
Pass Can wrap and unwrap Ed448 private key keys using jwk and AES-GCM
257+
Pass Can wrap and unwrap Ed448 private key keys as non-extractable using jwk and AES-GCM
258+
Pass Can unwrap Ed448 private key non-extractable keys using jwk and AES-GCM
231259
Pass Can wrap and unwrap X25519 public key keys using spki and AES-GCM
232260
Pass Can wrap and unwrap X25519 public key keys using jwk and AES-GCM
233261
Pass Can wrap and unwrap X25519 private key keys using pkcs8 and AES-GCM
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>WebCryptoAPI: generateKey() for Failures</title>
4+
<meta name="timeout" content="long">
5+
<script>
6+
self.GLOBAL = {
7+
isWindow: function() { return true; },
8+
isWorker: function() { return false; },
9+
isShadowRealm: function() { return false; },
10+
};
11+
</script>
12+
<script src="../../resources/testharness.js"></script>
13+
<script src="../../resources/testharnessreport.js"></script>
14+
<script src="../util/helpers.js"></script>
15+
<script src="failures.js"></script>
16+
<div id=log></div>
17+
<script src="../../WebCryptoAPI/generateKey/failures_Ed448.https.any.js"></script>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// META: title=WebCryptoAPI: generateKey() for Failures
2+
// META: timeout=long
3+
// META: script=../util/helpers.js
4+
// META: script=failures.js
5+
run_test(["Ed448"]);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>WebCryptoAPI: generateKey() Successful Calls</title>
4+
<meta name="timeout" content="long">
5+
<script>
6+
self.GLOBAL = {
7+
isWindow: function() { return true; },
8+
isWorker: function() { return false; },
9+
isShadowRealm: function() { return false; },
10+
};
11+
</script>
12+
<script src="../../resources/testharness.js"></script>
13+
<script src="../../resources/testharnessreport.js"></script>
14+
<script src="../util/helpers.js"></script>
15+
<script src="../../common/subset-tests.js"></script>
16+
<script src="successes.js"></script>
17+
<div id=log></div>
18+
<script src="../../WebCryptoAPI/generateKey/successes_Ed448.https.any.js"></script>

0 commit comments

Comments
 (0)