You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could implement an abstract class ByteBasedSecureRandom that extends SecureRandom and implements all of it functions based on nextBytes. Then, it is easy to extend this ByteBasedSecureRandom with a custom algorithm that puts out bytes.
I'm thinking about something like
import'dart:typed_data';
import'package:pointycastle/api.dart';
abstractclassByteBasedSecureRandomimplementsSecureRandom {
@overrideBigIntnextBigInteger(int bitLength) {
int byteCount = (bitLength +7) ~/8;
Uint8List bytes =nextBytes(byteCount);
String s ='';
for (int i =0; i < byteCount; i++) {
s = s + (bytes[i].toRadixString(2).padLeft(8, '0'));
}
returnBigInt.parse(s, radix:2).toUnsigned(bitLength);
}
@overrideintnextUint16() {
returnnextBytes(2).buffer.asByteData().getUint16(0);
}
@overrideintnextUint32() {
returnnextBytes(4).buffer.asByteData().getUint32(0);
}
@overrideintnextUint8() {
returnnextBytes(1).buffer.asByteData().getUint8(0);
}
@overridevoidseed(CipherParameters params) {}
}
While this might be slow (especially the nextBigInteger part), it was pointed out in #87 that
This package is pure Dart, completely software implementation, so it is slow.
so I see no problem with speed.
The idea behind this byte based approach is to then implement a Random on top of dart's own Random.secure, like
We could implement an abstract class
ByteBasedSecureRandom
that extends SecureRandom and implements all of it functions based onnextBytes
. Then, it is easy to extend thisByteBasedSecureRandom
with a custom algorithm that puts out bytes.I'm thinking about something like
While this might be slow (especially the
nextBigInteger
part), it was pointed out in #87 thatso I see no problem with speed.
The idea behind this byte based approach is to then implement a Random on top of dart's own
Random.secure
, likeThe text was updated successfully, but these errors were encountered: