flutter_mldsa 0.1.5 copy "flutter_mldsa: ^0.1.5" to clipboard
flutter_mldsa: ^0.1.5 copied to clipboard

Pointycastle interface implentations for MlDsa using bindings to RustCrypto implementation of ml-dsa

Flutter MlDsa #

Pointycastle interface implentations for MlDsa using bindings to RustCrypto implementation of ml-dsa

⚠️ Security Warning #

The implementation contained in this crate has never been independently audited!

USE AT YOUR OWN RISK!

If you have discovered a security vulnerability in this project, please report it privately. Do not disclose it as a public issue. This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. See SECURITY.md for more details.

Getting started #

Add flutter_mldsa and pointycastle to your dependencies

flutter pub add flutter_mldsa pointycastle

Usage #

  1. Initialize the FlutterMldsa:
await FlutterMldsa.init();
  1. Create a MlDsaKeyGenerator:
final keyGenerator = MlDsaKeyGenerator();

OR

final keyGenerator = KeyGenerator('Mldsa'); //Case sensitive
  1. Initialize the generator with a mode to generate
final generatorParams = MlDsaKeyGeneratorParams(mlDsaMode: MlDsaMode.MLDSA44);
keyGenerator.init(generatorParams);
  1. Generate a keypair:
final keypairA = keyGenerator.generateKeyPair();
  1. Create a Signer and initialize it:
final signer = MlDsaSigner();
signer.init(true, PrivateKeyParameter<MlDsaPrivateKey>(keypairA.privateKey));
  1. Create a verify and Initialize it:
final verifier = MlDsaSigner();
verifier.init(false, PublicKeyParameter<MlDsaPublicKey>(keypairA.publicKey));
  1. Use the MlDsaSigner functions to sign and verify:
final signature = signer.generateSignature(message);
final result = verifier.verifySignature(message, signature);
  1. (End of usage) Dispose the FlutterMldsa:
FlutterMldsa.dispose();

Web Support via WASM #

flutter_mldsa supports web by compiling the rust side to WASM, with some caveats.

Steps #

  1. You will need the flutter_rust_bridge_codegen tool, install it with cargo:
cargo install flutter_rust_bridge_codegen
  1. Navigate to your pub cache directory (usually $HOME/.pub-cache) and find flutter_mldsa, for example
cd $HOME/.pub-cache/hosted/pub.flutter-io.cn/flutter_mldsa-$VERSION/

where $VERSION is the version you are using

  1. Build the library for web (you will need the nightly rust compiler installed on your machine)
flutter_rust_bridge_codegen build-web --release

Note: The --release flag is needed because of the size of the keypair in Mldsa 87. Otherwise, you will get a Memory out of Bounds error.

  1. Copy the built files in web/pkg to your app's web/pkg directory.
mkdir -p $PROJECT_ROOT/web/pkg
cp web/pkg/* $PROJECT_ROOT/web/pkg

where $PROJECT_ROOT is your app's root directory

  1. Run your application with the --wasm flag
flutter run -d chrome --wasm

For an example build script, see the Makefile in the example

Testing #

Rust-Side #

cd rust
cargo test -- --show-output

Flutter-Side #

cd example
flutter test -d $DEVICE integration_test/master_integration_test.dart

where $DEVICE is set to a device on the platform you want to test (for example linux, emulator-5554)

Flutter web #

cd example
CHROMEDRIVER=path/to/chromedriver make test-web

License #

Licensed at:

0
likes
135
points
30
downloads

Publisher

unverified uploader

Weekly Downloads

Pointycastle interface implentations for MlDsa using bindings to RustCrypto implementation of ml-dsa

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

equatable, flutter, flutter_rust_bridge, plugin_platform_interface, pointycastle

More

Packages that depend on flutter_mldsa

Packages that implement flutter_mldsa