indcpaenc function
Implementation
void indcpaenc(Uint8List c, Uint8List m, Uint8List pk, Uint8List coins) {
Uint8List publicseed = pk.sublist(KYBER_POLYVECCOMPRESSEDBYTES, KYBER_POLYVECCOMPRESSEDBYTES+KYBER_SYMBYTES);
PolyVec pkvec = polyvecdecompress(pk.sublist(0, KYBER_POLYVECCOMPRESSEDBYTES));
List<List<Poly>> at = genMatrix(publicseed, true);
PolyVec r = PolyVec();
PolyVec e1 = PolyVec();
Poly e2 = Poly();
for (int i = 0; i < KYBER_K; i++) {
polygetnoise(r.vec[i], coins, i);
polygetnoise(e1.vec[i], coins, i+KYBER_K);
}
polygetnoise(e2, coins, 2*KYBER_K);
polyvecntt(r);
PolyVec u = PolyVec();
for (int i = 0; i < KYBER_K; i++) {
u.vec[i] = Poly();
for (int j = 0; j < KYBER_K; j++) {
Poly t = polybasemul(at[i][j], r.vec[j]);
if (j == 0) {
u.vec[i] = t;
} else {
u.vec[i] = polyadd(u.vec[i], t);
}
}
u.vec[i] = polyadd(u.vec[i], e1.vec[i]);
}
Poly v = Poly();
v.coeffs.fillRange(0, KYBER_N, 0);
for (int i = 0; i < KYBER_K; i++) {
Poly t = polybasemul(pkvec.vec[i], r.vec[i]);
v = polyadd(v, t);
}
polyfrommsg(e2, m);
v = polyadd(v, e2);
Uint8List ubytes = polyveccompress(u);
Uint8List vbytes = polycompress(v);
for (int i = 0; i < ubytes.length; i++) {
c[i] = ubytes[i];
}
for (int i = 0; i < vbytes.length; i++) {
c[ubytes.length + i] = vbytes[i];
}
}