ChaCha22 constructor
ChaCha22(
{ - required List<int> key,
- required List<int> nonce,
- int nonceInplaceCounterLength = 0,
})
Implementation
ChaCha22({
required this.key,
required List<int> nonce,
int nonceInplaceCounterLength = 0,
}) {
// We only support 256-bit keys.
if (key.length != 32) {
throw ArgumentException.invalidOperationArguments(
"streamXOR",
name: "key",
reason: "Invalid key bytes length.",
);
}
List<int> nc;
int counterLength;
if (nonceInplaceCounterLength == 0) {
if (nonce.length != 8 && nonce.length != 12) {
throw ArgumentException.invalidOperationArguments(
"streamXOR",
name: "nonce",
reason: "Invalid nonce bytes length.",
);
}
nc = List<int>.filled(16, 0);
counterLength = nc.length - nonce.length;
nc.setAll(counterLength, nonce);
} else {
if (nonce.length != 16) {
throw ArgumentException.invalidOperationArguments(
"streamXOR",
name: "nonce",
reason: "Invalid nonce bytes length.",
);
}
nc = nonce;
counterLength = nonceInplaceCounterLength;
}
this.nonce = nc;
this.counterLength = counterLength;
}