diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-10-03 16:46:48 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-03 16:46:48 +0530 |
commit | e54809f2d56c8e91089d55d60e674cba37fd2863 (patch) | |
tree | 7dfbf4025488c86eeaeec4a6be84b94935f9e148 /tests/unit | |
parent | ac73b1042b4dda6416ad82d5468c57de6d53d038 (diff) |
fix(ext/crypto): fix identity test for x25519 derive bits (#26011)
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/webcrypto_test.ts | 40 |
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)); +}); |