bitsToOctetsWithOrderPadding static method
Converts a sequence of bits represented as a byte array to octets.
This method takes a byte array 'data' containing a sequence of bits and converts it to octets by first converting it to a BigInt 'z1' and then computing 'z2' as 'z1' modulo 'order'. If 'z2' is negative, it is replaced with 'z1'. The resulting 'z2' is then converted to a byte array with padding to match the length of 'order' in octets.
Parameters:
- data: A List
- order: A BigInt representing the order of a cryptographic curve.
Returns:
- List
Details:
- The method first converts the binary data to a BigInt 'z1'.
- It then computes 'z2' by taking 'z1' modulo 'order' and ensures that 'z2' is not negative; if it is, 'z2' is replaced with 'z1'.
- Finally, 'z2' is converted to a byte array with padding to match the length of 'order' in octets. The output is a byte array suitable for cryptographic use.
Implementation
static List<int> bitsToOctetsWithOrderPadding(List<int> data, BigInt order) {
BigInt z1 = bitsToBigIntWithLengthLimit(data, order.bitLength);
BigInt z2 = z1 - order;
if (z2 < BigInt.zero) {
z2 = z1;
}
final bytes = bigintToBytesWithPadding(z2, order);
return bytes;
}