Skip to content

Poly1305 / ChaCha20Poly1305 throw "full width integer not supported" on web (dart2js) in 4.0.0 #265

Open

Description

@gmpassos

Summary

Poly1305 — and therefore ChaCha20Poly1305 — cannot be used when compiled to JavaScript. The constructors call Platform.instance.assertFullWidthInteger() (lib/macs/poly1305.dart, lines 20 and 25 in 4.0.0), which throws full width integer not supported on this platform on dart2js.

This was raised in comments on #126 (2022, 2023). That issue was about Argon2, which has since gained a Register64-based implementation for the web, but Poly1305 still has the guard, so I'm opening a focused issue with a current reproduction.

Reproduction

pubspec.yaml: pointycastle: 4.0.0, Dart SDK 3.13.5.

import 'dart:typed_data';
import 'package:pointycastle/export.dart';

void main() {
  try {
    Poly1305();
    print('Poly1305(): ok');
  } catch (e) {
    print('Poly1305(): $e');
  }
  try {
    final cipher = ChaCha20Poly1305(ChaCha7539Engine(), Poly1305())
      ..init(true, AEADParameters(KeyParameter(Uint8List(32)), 128, Uint8List(12), Uint8List(0)));
    final input = Uint8List(16);
    final out = Uint8List(cipher.getOutputSize(input.length));
    cipher.doFinal(out, cipher.processBytes(input, 0, input.length, out, 0));
    print('ChaCha20Poly1305: ok');
  } catch (e) {
    print('ChaCha20Poly1305: $e');
  }
}

Dart VM (dart run):

Poly1305(): ok
ChaCha20Poly1305: ok

dart2js (dart compile js then run in node with globalThis.self = globalThis; same result in Chrome via dart test -p chrome):

Poly1305(): full width integer not supported on this platform
ChaCha20Poly1305: full width integer not supported on this platform

Expected

Either a web-compatible Poly1305, as was done for Argon2 (Poly1305 only needs 26-bit limbs × 32-bit multiplies, as in the poly1305-donna 32-bit variant, so it fits within JS integer precision), or documentation that Poly1305 / ChaCha20Poly1305 are VM-only.

Context

Found while adding ChaCha20-Poly1305 support to a library that targets the VM, dart2js and dart2wasm. dart2wasm is unaffected (it has 64-bit integers); only dart2js fails.

Activity

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