1

i have an error with Uint64List in flutter Web (in pointycastle lib)

var length = Uint8List.view((Uint64List(2)..[0] = iv.length * 8).buffer);

"Error: Unsupported operation: Uint64List not supported on the web.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/typed_data_patch.dart 115:5       new
packages/pointycastle/block/modes/gcm.dart 81:36                              [_computeInitialCounter]
packages/pointycastle/block/modes/gcm.dart 61:16                              prepare
packages/pointycastle/src/impl/base_aead_block_cipher.dart 217:5              reset
packages/pointycastle/block/modes/gcm.dart 47:11                              reset
packages/pointycastle/src/impl/base_aead_block_cipher.dart 117:5              init
packages/pointycastle/block/modes/gcm.dart 40:11                              init
packages/crypto_keys/src/symmetric_operator.dart 71:16                        encrypt

Do you know how to fix that ? Thx

redDwarf
  • 336
  • 1
  • 9
  • If you need to use 64-bit numbers portably (but sacrificing speed) for both the VM and for the web, use [`package:fixnum`](https://pub.dev/packages/fixnum). – jamesdlin Nov 21 '22 at 17:59
  • That's not going to work on web. You could easily re-write it using `Uint32List(4)..` etc (and then submit a PR and close your own issue) – Richard Heap Nov 21 '22 at 21:40
  • Can you accept the answer as presumably the proposed changed worked. – Richard Heap Jan 07 '23 at 02:26
  • I hope the PR will be validated one day :) https://github.com/bcgit/pc-dart/pull/181 – redDwarf Jan 08 '23 at 08:24

2 Answers2

0

For all practical values of IV length, you can fit the value in a 32 bit int. The following equivalent code runs fine in Dartpad and gives the same result as the above code in VM.

import 'dart:typed_data';

void main() {
  final iv = Uint8List(12);

  final length = Uint8List.view((Uint32List(4)..[0] = iv.length * 8).buffer);

  print(length);
}

And, similarly, this:

var len = Uint8List.view((Uint32List(4)
      ..[2] = aad!.length * 8
      ..[0] = _processedBytes * 8)
    .buffer);
Richard Heap
  • 48,344
  • 9
  • 130
  • 112
0

Thx And about please ?

 @override
  int doFinal(Uint8List out, int outOff) {
    var result = remainingInput.isNotEmpty
        ? processBlock(remainingInput, 0, out, outOff)
        : 0;

    var len = Uint8List.view((Uint64List(2)
          ..[1] = aad!.length * 8
          ..[0] = _processedBytes * 8)
        .buffer);
    len = Uint8List.fromList(len.reversed.toList());

    _gHASHBlock(_x, len);

    _xor(_x, _e0);

    if (forEncryption) {
      out.setAll(outOff + result, _x);
      result += _x.length;
    }

    validateMac();

    return result;
  }
redDwarf
  • 336
  • 1
  • 9