-
Notifications
You must be signed in to change notification settings - Fork 92
Document and test maximum deriveBits length for ECDH curves #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -314,6 +314,73 @@ void main() { | |
| ); | ||
| }); | ||
| }); | ||
| group('ECDH deriveBits', () { | ||
| test('P-256 allows maximum deriveBits length', () async { | ||
| final aliceKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); | ||
| final bobKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); | ||
|
|
||
| final secret = await aliceKeyPair.privateKey.deriveBits( | ||
| 256, | ||
| bobKeyPair.publicKey, | ||
| ); | ||
|
|
||
| expect(secret.length, equals(32)); | ||
| }); | ||
|
|
||
| test('P-256 rejects deriveBits larger than maximum', () async { | ||
| final aliceKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); | ||
| final bobKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); | ||
|
|
||
| expect( | ||
| aliceKeyPair.privateKey.deriveBits(257, bobKeyPair.publicKey), | ||
| throwsA(anyOf(isA<subtle.JSDomException>(), isA<Error>())), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this implies a different kind of issue. I think we are supposed to catch JSDomException and make it into an Exception or an Error.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear that is probably an orthogonal issue to this PR and should be fixed separately.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since it’s kind of a separate thing, I will leave it out of this PR for now so this doesn’t get messy. I can open a new issue for the JSDomException part if needed. |
||
| ); | ||
| }); | ||
|
|
||
| test('P-384 allows maximum deriveBits length', () async { | ||
| final aliceKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p384); | ||
| final bobKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p384); | ||
|
|
||
| final secret = await aliceKeyPair.privateKey.deriveBits( | ||
| 384, | ||
| bobKeyPair.publicKey, | ||
| ); | ||
|
|
||
| expect(secret.length, equals(48)); | ||
| }); | ||
|
|
||
| test('P-384 rejects deriveBits larger than maximum', () async { | ||
| final aliceKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p384); | ||
| final bobKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p384); | ||
|
|
||
| expect( | ||
| aliceKeyPair.privateKey.deriveBits(385, bobKeyPair.publicKey), | ||
| throwsA(anyOf(isA<subtle.JSDomException>(), isA<Error>())), | ||
| ); | ||
| }); | ||
|
|
||
| test('P-521 allows maximum deriveBits length', () async { | ||
| final aliceKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p521); | ||
| final bobKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p521); | ||
|
|
||
| final secret = await aliceKeyPair.privateKey.deriveBits( | ||
| 528, | ||
| bobKeyPair.publicKey, | ||
| ); | ||
|
|
||
| expect(secret.length, equals(66)); | ||
| }); | ||
|
|
||
| test('P-521 rejects deriveBits larger than maximum', () async { | ||
| final aliceKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p521); | ||
| final bobKeyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p521); | ||
|
|
||
| expect( | ||
| aliceKeyPair.privateKey.deriveBits(529, bobKeyPair.publicKey), | ||
| throwsA(anyOf(isA<subtle.JSDomException>(), isA<Error>())), | ||
| ); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| extension on JSArray<JSString> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should decidedly not live in
test/crypto_subtle_test.dart--- this tests thesubtle.window.crypto.subtlewrapper we have.I suggest we put them in
lib/src/testing/ecdh/derive_bits.dartortest/ecdh_derive_bits_test.dart(they won't be included in integration tests, but maybe that's okay -- we can always move them later, and getting coverage is probably better).I don't mind these tests, but they could also be made much simpler.