indcpadec function

void indcpadec(
  1. Uint8List m,
  2. Uint8List c,
  3. Uint8List sk
)

Decapsulates a ciphertext to recover the original message using the secret key.

This function takes a ciphertext c and a secret key sk, then utilizes polynomial arithmetic to recover the original message m. The ciphertext is decompressed into two components, u and v. The secret key is interpreted as a polynomial vector s. The function computes the inner product of u and s, subtracts it from v, and converts the result back into the original message format.

@paramout m The recovered message. @paramin c The ciphertext to be decapsulated. @paramin sk The secret key used for decapsulation.

Implementation

void indcpadec(Uint8List m, Uint8List c, Uint8List sk) {
  PolyVec u = polyvecdecompress(c.sublist(0, KYBER_POLYVECCOMPRESSEDBYTES));
  Poly v = polydecompress(c.sublist(KYBER_POLYVECCOMPRESSEDBYTES));

  PolyVec s = polyvecfrombytes(sk);

  Poly tmp = Poly();
  tmp.coeffs.fillRange(0, KYBER_N, 0);
  for (int i = 0; i < KYBER_K; i++) {
    Poly t = polybasemul(u.vec[i], s.vec[i]);
    tmp = polyadd(tmp, t);
  }

  Poly mp = polysub(v, tmp);
  polytomsg(m, mp);
}