jspschool / tweetnacl-dart

Port of TweetNaCl cryptographic library to Dart.
MIT License
6 stars 20 forks source link

It is wrong in release mode of flutter #3

Closed imloama closed 5 years ago

imloama commented 5 years ago

from the same seed, I got two different result in modes of debug and release

environment:

• Flutter version 1.5.4 • Framework revision b593f5167b (3 months ago), 2019-04-22 07:51:33 -0700 • Engine revision ca31a7c57b • Dart version 2.3.0 (build 2.3.0-dev.0.1 cf4444b803)

import 'package:tweetnacl/tweetnacl.dart' as ED25519;
import 'package:hex/hex.dart';

final seed = HEX.decode("4d691bc19b44a1383b1a0a130aaca3e05c3c1a371dbe45930ef9b761f7a74691");

final signature = ED25519.Signature.keyPair_fromSeed(seed);

print(HEX.encode(signature.publicKey));
GreenAppers commented 5 years ago

Try upgrading to latest Flutter stable, e.g. 1.7.x. That fixed it for me.

I narrowed the issue down to the _pack25519 function after https://github.com/jspschool/tweetnacl-dart/blob/master/lib/src/tweetnacl_base.dart#L1503 Then it went Heisenbug. (After I add debugPrint()s to the rest of _pack25519 the issue stops reproducing)

I'd say this has to be a Dart bug.

It's always a good practice to run a unit test with an objective test vector before any highly sensitive cryptography (e.g. sending a cryptocurrency transaction)

imloama commented 5 years ago

Thanks @GreenAppers I test it in flutter,version 1.7.8, and it works well.