Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/src/testing/webcrypto/ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,32 @@ final runner = TestRunner.asymmetric<EcdhPrivateKey, EcdhPublicKey>(
);

void main() async {
log('generate ECDH test case');
log('generate ECDH test cases');

// P-256: up to 256 bits (32 bytes)
await runner.generate(
generateKeyParams: {'curve': curveToJson(EllipticCurve.p256)},
importKeyParams: {'curve': curveToJson(EllipticCurve.p256)},
deriveParams: {},
maxDeriveLength: 32,
);

// P-384: up to 384 bits (48 bytes)
await runner.generate(
generateKeyParams: {'curve': curveToJson(EllipticCurve.p384)},
importKeyParams: {'curve': curveToJson(EllipticCurve.p384)},
deriveParams: {},
maxDeriveLength: 48,
);

// P-521: up to 528 bits (66 bytes)
await runner.generate(
generateKeyParams: {'curve': curveToJson(EllipticCurve.p521)},
importKeyParams: {'curve': curveToJson(EllipticCurve.p521)},
deriveParams: {},
maxDeriveLength: 66,
);

log('--------------------');

await runner.tests().runTests();
Expand Down
9 changes: 5 additions & 4 deletions lib/src/webcrypto/webcrypto.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ final class EcdhPrivateKey {
/// two parties.
///
/// [length] specifies the length of the derived secret in bits.
/// The maximum length depends on the [EllipticCurve] used:
/// * [EllipticCurve.p256] — up to 256 bits.
/// * [EllipticCurve.p384] — up to 384 bits.
/// * [EllipticCurve.p521] — up to 528 bits.
///
/// [publicKey] is [EcdhPublicKey] from the other party's ECDH key pair.
///
/// Returns a [Uint8List] containing the derived shared secret.
///
/// {@macro EcdhPrivateKey:example}
// Note some webcrypto implementations (chrome, not firefox) supports passing
// null for length (in this primitive). However, you can always know the right
// length from the curve. Note p512 can provide up to: 528 bits!!!
//
// See: https://www.rfc-editor.org/rfc/rfc6090#section-4
// Notice that this is not uniformly distributed, see also:
// https://www.rfc-editor.org/rfc/rfc6090#appendix-B
Expand Down