#include #include "indcpa.h" #include "poly.h" #include "polyvec.h" #include "randombytes.h" #include "fips202.h" #include "ntt.h" /************************************************* * Name: pack_pk * * Description: Serialize the public key as concatenation of the * compressed and serialized vector of polynomials pk * and the public seed used to generate the matrix A. * * Arguments: unsigned char *r: pointer to the output serialized public key * const poly *pk: pointer to the input public-key polynomial * const unsigned char *seed: pointer to the input public seed **************************************************/ static void pack_pk(unsigned char *r, const polyvec *pk, const unsigned char *seed) { int i; polyvec_compress(r, pk); for(i=0;i SHAKE128_RATE*nblocks-2) { nblocks = 1; shake128_squeezeblocks(buf,nblocks,state); pos = 0; } } } } } /************************************************* * Name: indcpa_keypair * * Description: Generates public and private key for the CPA-secure * public-key encryption scheme underlying Kyber * * Arguments: - unsigned char *pk: pointer to output public key (of length KYBER_INDCPA_PUBLICKEYBYTES bytes) * - unsigned char *sk: pointer to output private key (of length KYBER_INDCPA_SECRETKEYBYTES bytes) **************************************************/ void indcpa_keypair(unsigned char *pk, unsigned char *sk) { polyvec a[KYBER_K], e, pkpv, skpv; unsigned char buf[KYBER_SYMBYTES+KYBER_SYMBYTES]; unsigned char *publicseed = buf; unsigned char *noiseseed = buf+KYBER_SYMBYTES; int i; unsigned char nonce=0; randombytes(buf, KYBER_SYMBYTES); sha3_512(buf, buf, KYBER_SYMBYTES); gen_a(a, publicseed); for(i=0;i