summaryrefslogtreecommitdiff
path: root/tests/unit/webcrypto_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/webcrypto_test.ts')
-rw-r--r--tests/unit/webcrypto_test.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/unit/webcrypto_test.ts b/tests/unit/webcrypto_test.ts
index 57aa19eae..09552a058 100644
--- a/tests/unit/webcrypto_test.ts
+++ b/tests/unit/webcrypto_test.ts
@@ -2045,3 +2045,43 @@ Deno.test(async function p521Generate() {
assert(key.privateKey instanceof CryptoKey);
assert(key.publicKey instanceof CryptoKey);
});
+
+Deno.test(async function x25519SharedSecret() {
+ const alicesKeyPair = await crypto.subtle.generateKey(
+ {
+ name: "X25519",
+ },
+ false,
+ ["deriveBits"],
+ ) as CryptoKeyPair;
+
+ const bobsKeyPair = await crypto.subtle.generateKey(
+ {
+ name: "X25519",
+ },
+ false,
+ ["deriveBits"],
+ ) as CryptoKeyPair;
+
+ const sharedSecret1 = await crypto.subtle.deriveBits(
+ {
+ name: "X25519",
+ public: bobsKeyPair.publicKey,
+ },
+ alicesKeyPair.privateKey,
+ 128,
+ );
+
+ const sharedSecret2 = await crypto.subtle.deriveBits(
+ {
+ name: "X25519",
+ public: alicesKeyPair.publicKey,
+ },
+ bobsKeyPair.privateKey,
+ 128,
+ );
+
+ assertEquals(sharedSecret1.byteLength, sharedSecret2.byteLength);
+ assertEquals(sharedSecret1.byteLength, 16);
+ assertEquals(new Uint8Array(sharedSecret1), new Uint8Array(sharedSecret2));
+});