Skip to content

Full width int not supported on web #126

Open

Description

@leoca-dev

I took this example from the Argon2 test:

final parameters = Argon2Parameters(
  Argon2Parameters.ARGON2_d,
  latin1.encode('mySaltString'),
  desiredKeyLength: 32,
  version: Argon2Parameters.ARGON2_VERSION_10,
  iterations: 3,
  memoryPowerOf2: 32,
);

final gen = Argon2BytesGenerator()..init(parameters);
final valueBytes = Uint8List.fromList(utf8.encode(value));
final result = gen.process(valueBytes);

return String.fromCharCodes(result);

But when I use it on Google Chrome I get this exception:

Error: full width integer not supported on this platform
    at Object.throw_ [as throw] (http://localhost:64504/dart_sdk.js:5348:11)
    at web.PlatformWeb.new.assertFullWidthInteger (http://localhost:64504/packages/pointycastle/src/platform_check/web.dart.lib.js:35:19)
    at new argon2.Argon2BytesGenerator.new (http://localhost:64504/packages/pointycastle/ecc/curves/secp521r1.dart.lib.js:8488:38)
    at hash (http://localhost:64504/packages/passy/features/data/hasher.dart.lib.js:47:26)
    at hash.next (<anonymous>)
    at runBody (http://localhost:64504/dart_sdk.js:39250:34)
    at Object._async [as async] (http://localhost:64504/dart_sdk.js:39281:7)
    at hasher.Hasher.new.hash (http://localhost:64504/packages/passy/features/data/hasher.dart.lib.js:44:20)
    at main$ (http://localhost:64504/packages/passy/main.dart.lib.js:580:107)
    at main$.next (<anonymous>)
    at runBody (http://localhost:64504/dart_sdk.js:39250:34)
    at Object._async [as async] (http://localhost:64504/dart_sdk.js:39281:7)
    at main$ (http://localhost:64504/packages/passy/main.dart.lib.js:576:18)
    at main (http://localhost:64504/web_entrypoint.dart.lib.js:36:29)
    at main.next (<anonymous>)
    at http://localhost:64504/dart_sdk.js:39230:33
    at _RootZone.runUnary (http://localhost:64504/dart_sdk.js:39087:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:64504/dart_sdk.js:34073:29)
    at handleValueCallback (http://localhost:64504/dart_sdk.js:34633:49)
    at Function._propagateToListeners (http://localhost:64504/dart_sdk.js:34671:17)
    at _Future.new.[_completeWithValue] (http://localhost:64504/dart_sdk.js:34513:23)
    at http://localhost:64504/dart_sdk.js:33724:46

And when I try it on an android device I get this error:

E/flutter ( 8615): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Out of Memory
E/flutter ( 8615): #0      new _List (dart:core-patch/array.dart)
E/flutter ( 8615): #1      List._allocateData (dart:core-patch/growable_array.dart:356:16)
E/flutter ( 8615): #2      new _GrowableList (dart:core-patch/growable_array.dart:97:16)
E/flutter ( 8615): #3      new _GrowableList.generate (dart:core-patch/growable_array.dart:131:20)
E/flutter ( 8615): #4      Argon2BytesGenerator._initMemory
package:pointycastle/key_derivators/argon2.dart:141
E/flutter ( 8615): #5      Argon2BytesGenerator._doInit
package:pointycastle/key_derivators/argon2.dart:137
E/flutter ( 8615): #6      Argon2BytesGenerator.init
package:pointycastle/key_derivators/argon2.dart:90
E/flutter ( 8615): #7      Hasher.hash
package:passy/…/data/hasher.dart:38
E/flutter ( 8615): #8      main
package:passy/main.dart:30
E/flutter ( 8615): #9      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25)
E/flutter ( 8615): #10     _rootRun (dart:async/zone.dart:1354:13)
E/flutter ( 8615): #11     _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter ( 8615): #12     _runZoned (dart:async/zone.dart:1789:10)
E/flutter ( 8615): #13     runZonedGuarded (dart:async/zone.dart:1777:12)
E/flutter ( 8615): #14     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5)
E/flutter ( 8615): #15     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter ( 8615): #16     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Am I calling the library with wrong parameters? If so, how should I use it?

Flutter version: 2.2.3
Windows: 10
Android: 11
Chrome version: 92.0.4515.107

Activity

  1. AKushWarrior commented on Aug 4, 2021

    @AKushWarrior
    Contributor

    Argon2 is not supported on web currently; it requires 64-bit integers, and we have no way to simulate that behavior from Dart code compiled to JS.

    The Android one is a bug.

  2. leoca-dev commented on Aug 4, 2021

    @leoca-dev
    Author

    Argon2 is not supported on web currently; it requires 64-bit integers, and we have no way to simulate that behavior from Dart code compiled to JS.

    The Android one is a bug.

    Shouldn't be possibile to use the BigInt to represent such large numbers? 🤔 never tested but both Dart and JS has this class to represent integers larger than 2^53-1

  3. licy183 commented on Aug 31, 2021

    @licy183
    Contributor

    PR #133 may be helpful. But I don't think implementing argon2 in pure dart is a good choice.

  4. willbinge commented on Apr 8, 2022

    @willbinge

    Are there plans to make a similar fix for Poly1305, which still has the calls to assertFullWidthInteger?

  5. levischechter commented on May 17, 2023

    @levischechter

    Are there plans to make a similar fix for Poly1305, which still has the calls to assertFullWidthInteger?

    join the question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions