crypto/ringlwe/ringlwe_kex.c
/* Encapsulation routine. Returns an element in R_q x R_2
 * input:  Alice's public key b in Fourier Domain
 * output: Bob's public key u in Fourier Domain
 *         reconciliation data cr_v
 *         shared secret mu
 */
Encapsulation routine. Returns an element in R_q x R_2
input:  Alice's public key b in Fourier Domain
output: Bob's public key u in Fourier Domain
reconciliation data cr_v
shared secret mu
Encapsulation routine . Returns an element in R_q x R_2 input : Alice ' s public key b in Fourier Domain output : Bob ' s public key u in Fourier Domain reconciliation data cr_v shared secret mu
void KEM1_Encapsulate(RINGELT *u, 
		      uint64_t *cr_v, 
		      uint64_t *mu, 
		      const RINGELT *b, 
		      const RINGLWE_PARAM_DATA *p) {
  const RINGELT m=p->m, q=p->q;
  RINGELT e[3*p->m];
  RINGELT v[p->m];
  sample_secret(e, p);
  sample_secret(e+m, p);
  sample_secret(e+2*m, p);	
  assert(p->fft_forward);
  assert(p->fft_backward);
  p->fft_forward((FFTSHORT *)e);
  p->fft_forward((FFTSHORT *)(e+m));
  POINTWISE_MUL_ADD(u, p->a, e, e+m, m, q);
  POINTWISE_MUL(v, b, e, m, q); 
  p->fft_backward((FFTSHORT *)v); 
  if ((m)&1) 
    MAPTOCYCLOTOMIC(v, m, q);
  POINTWISE_ADD(v, v, e+2*m, m, q); 
  round_and_cross_round(mu, cr_v, v, p);
  memset(e, 0, 3*p->m * sizeof(RINGELT));
  memset(v, 0, p->m * sizeof(RINGELT));
}
void KEM1_Encapsulate ( RINGELT * u , uint64_t * cr_v , uint64_t * mu , const RINGELT * b , const RINGLWE_PARAM_DATA * p ) { const RINGELT m = p -> m , q = p -> q ; RINGELT e [ 3 * p -> m ] ; RINGELT v [ p -> m ] ; sample_secret ( e , p ) ; sample_secret ( e + m , p ) ; sample_secret ( e + 2 * m , p ) ; assert ( p -> fft_forward ) ; assert ( p -> fft_backward ) ; p -> fft_forward ( ( FFTSHORT * ) e ) ; p -> fft_forward ( ( FFTSHORT * ) ( e + m ) ) ; POINTWISE_MUL_ADD ( u , p -> a , e , e + m , m , q ) ; POINTWISE_MUL ( v , b , e , m , q ) ; p -> fft_backward ( ( FFTSHORT * ) v ) ; if ( ( m ) & 1 ) MAPTOCYCLOTOMIC ( v , m , q ) ; POINTWISE_ADD ( v , v , e + 2 * m , m , q ) ; round_and_cross_round ( mu , cr_v , v , p ) ; memset ( e , 0 , 3 * p -> m * sizeof ( RINGELT ) ) ; memset ( v , 0 , p -> m * sizeof ( RINGELT ) ) ; }
Encapsulation routine.
Encapsulation routine .
/*[m]*/ /*[muwords]*/ /*[muwords]*/ /*[m]*/ /*Sample Bob's ephemeral keys*/ /*Fourer Transform e0 and e1*/ /* Combine with a to produce e_0*a+e_1 in the Fourier domain. Bob's public key. */ /* Create v = e0*b */ /* Undo the Fourier Transform */ /* prime case */ /* Create v = e0*b+e2 */