`Blake2bDigest` with explicit key triggers `RangeError`
Opened this issue · 2 comments
objectx commented
Following code should run without errors, but h.process
throws a RangeError
.
import 'dart:convert';
import 'dart:typed_data';
import 'package:typed_data/typed_data.dart';
import 'package:pointycastle/digests/blake2b.dart';
main() {
final enc = AsciiEncoder();
final key = enc.convert('foo');
//final key = null;
final h = Blake2bDigest(key: key, salt: makeBlake2Salt(enc.convert('bar')));
final msg = enc.convert('baz');
final out = h.process(msg);
print('out = ${_dumpHex(out)}');
}
Uint8List makeBlake2Salt(Uint8List s) {
final b = Uint8Buffer(16);
b
..fillRange(0, 16, 0)
..setRange(0, s.length, s);
assert(b.length == 16);
return b.buffer.asUint8List();
}
String _dumpHex(Uint8List l) {
return l.map((x) => x.toRadixString(16).padLeft(2, '0')).join('');
}
Digging into the source, I've found:
_bufferPos
was initialized to the end when the key was supplied.- in the 1st call of
update
, theremainingLength
is0
_compress
was called- the
unpack
triggers theRangeError
duanyytop commented
I have found another blake2b library which can work well. https://github.com/ilap/pinenacl-dart