polyfrommsg function
Converts a message byte array msg
into a polynomial p
.
This function interprets each byte in the message msg
as a series
of 8 bits, where each bit is mapped to a coefficient in the polynomial p
.
If the bit is set (1), the corresponding coefficient in p
is set to
KYBER_Q / 2
. If the bit is not set (0), the coefficient is set to 0.
The message msg
is expected to have KYBER_SYMBYTES
bytes, resulting
in a polynomial p
with coefficients that encode the message.
- Parameters:
- p: The polynomial to be populated with coefficients based on the message.
- msg: A byte array representing the message to be encoded into the polynomial.
Implementation
void polyfrommsg(Poly p, Uint8List msg) {
for (int i = 0; i < KYBER_SYMBYTES; i++) {
for (int j = 0; j < 8; j++) {
int bit = (msg[i] >> j) & 1;
p.coeffs[8 * i + j] = bit * (KYBER_Q ~/ 2);
}
}
}