| 15 | // Test ECDH bit derivation |
| 16 | { |
| 17 | async function test(namedCurve) { |
| 18 | const [alice, bob] = await Promise.all([ |
| 19 | subtle.generateKey({ name: 'ECDH', namedCurve }, true, ['deriveBits']), |
| 20 | subtle.generateKey({ name: 'ECDH', namedCurve }, true, ['deriveBits']), |
| 21 | ]); |
| 22 | |
| 23 | const [secret1, secret2] = await Promise.all([ |
| 24 | subtle.deriveBits({ |
| 25 | name: 'ECDH', namedCurve, public: alice.publicKey |
| 26 | }, bob.privateKey, 128), |
| 27 | subtle.deriveBits({ |
| 28 | name: 'ECDH', namedCurve, public: bob.publicKey |
| 29 | }, alice.privateKey, 128), |
| 30 | ]); |
| 31 | |
| 32 | assert(secret1 instanceof ArrayBuffer); |
| 33 | assert(secret2 instanceof ArrayBuffer); |
| 34 | assert.deepStrictEqual(secret1, secret2); |
| 35 | } |
| 36 | |
| 37 | test('P-521').then(common.mustCall()); |
| 38 | } |