flutter_mldsa 0.1.5
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 #
- Initialize the FlutterMldsa:
await FlutterMldsa.init();
- Create a MlDsaKeyGenerator:
final keyGenerator = MlDsaKeyGenerator();
OR
final keyGenerator = KeyGenerator('Mldsa'); //Case sensitive
- Initialize the generator with a mode to generate
final generatorParams = MlDsaKeyGeneratorParams(mlDsaMode: MlDsaMode.MLDSA44);
keyGenerator.init(generatorParams);
- Generate a keypair:
final keypairA = keyGenerator.generateKeyPair();
- Create a Signer and initialize it:
final signer = MlDsaSigner();
signer.init(true, PrivateKeyParameter<MlDsaPrivateKey>(keypairA.privateKey));
- Create a verify and Initialize it:
final verifier = MlDsaSigner();
verifier.init(false, PublicKeyParameter<MlDsaPublicKey>(keypairA.publicKey));
- Use the MlDsaSigner functions to sign and verify:
final signature = signer.generateSignature(message);
final result = verifier.verifySignature(message, signature);
- (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 #
- You will need the
flutter_rust_bridge_codegentool, install it with cargo:
cargo install flutter_rust_bridge_codegen
- 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
- 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.
- Copy the built files in
web/pkgto your app'sweb/pkgdirectory.
mkdir -p $PROJECT_ROOT/web/pkg
cp web/pkg/* $PROJECT_ROOT/web/pkg
where $PROJECT_ROOT is your app's root directory
- 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: